Skip to content

Instantly share code, notes, and snippets.

View kushti's full-sized avatar

Alexander Chepurnoy kushti

View GitHub Profile
object Tester extends App with ApiCodecs {
val s = "0e1631393039303063646462363930366462363530336665"
val et = ErgoTreeSerializer.DefaultSerializer.deserializeErgoTree(Base16.decode(s).get)
println(et)
val jsonString =
"""
|{
@kushti
kushti / NBitsTester.scala
Created October 17, 2023 13:39
NBitsTester.scala
import com.google.common.primitives.{Ints, Longs}
import org.ergoplatform.mining.difficulty.DifficultySerializer
object NBitsTester extends App {
val nb = 118012349L
val diff = DifficultySerializer.decodeCompactBits(nb)
println(nb.toBinaryString)
println(diff)
object SigmaBoolean extends App {
val addr = "9hUzb5RvSgDqJdtyCN9Ke496Yy63mpcUJKbRq4swzQ5EQKgygKT"
val eae = ErgoAddressEncoder.Mainnet
val script = eae.fromString("9hUzb5RvSgDqJdtyCN9Ke496Yy63mpcUJKbRq4swzQ5EQKgygKT").get.asInstanceOf[P2PKAddress].pubkey
val bsRaw = Base58.decode("9hUzb5RvSgDqJdtyCN9Ke496Yy63mpcUJKbRq4swzQ5EQKgygKT").get
val bs = bsRaw.tail.dropRight(4)
data_point_source: NanoErgXau
oracle_contract_parameters:
ergo_tree_bytes: 100a040004000580dac409040004000e203c45f29a5165b030fdb5eaf5d81f8108f9d8f507b31487dd51f4ae08fe07cf4a0402040204020402d804d601b2a5e4e3000400d602db63087201d603db6308a7d604e4c6a70407ea02d1ededed93b27202730000b2720373010093c27201c2a7e6c67201040792c172017302eb02cd7204d1ededededed938cb2db6308b2a4730300730400017305938cb27202730600018cb2720373070001918cb27202730800028cb272037309000293e4c672010407720492c17201c1a7efe6c672010561
pool_nft_index: 5
min_storage_rent_index: 2
min_storage_rent: 10000000
pool_contract_parameters:
ergo_tree_bytes: 1004040204000e2005fd350e60df5f35c1ca457687abf54e2f03b92f8e2c1ebbba912fc42acfeda40e20de408c789d16fb663f1daa87ce94bf38bf527ca067379308393f2a82ae1cafc5d801d6018cb2db6308b2a473000073010001d1ec93720173029372017303
refresh_nft_index: 2
update_nft_index: 3
data_point_source: NanoErgXau
oracle_contract_parameters:
ergo_tree_bytes: 100a040004000580dac409040004000e20472b4b6250655368566d597133743677397a24432646294a404d635166546a570402040204020402d804d601b2a5e4e3000400d602db63087201d603db6308a7d604e4c6a70407ea02d1ededed93b27202730000b2720373010093c27201c2a7e6c67201040792c172017302eb02cd7204d1ededededed938cb2db6308b2a4730300730400017305938cb27202730600018cb2720373070001918cb27202730800028cb272037309000293e4c672010407720492c17201c1a7efe6c672010561
pool_nft_index: 5
min_storage_rent_index: 2
min_storage_rent: 10000000
refresh_contract_parameters:
ergo_tree_bytes: 1016043c040004000e202a472d4a614e645267556b58703273357638792f423f4528482b4d625065536801000502010105000400040004020402040204080400040a05c8010e20472b4b6250655368566d597133743677397a24432646294a404d635166546a570400040404020408d80ed60199a37300d602b2a4730100d603b5a4d901036395e6c672030605eded928cc77203017201938cb2db6308720373020001730393e4c672030504e4c6720205047304d604b17203d605b0720386027305860273067307d90
object p2shTester extends App {
val p2shaddr = "4MQyML64GnzMxZgm"
val ae = ErgoAddressEncoder.Mainnet
val prop = ae.fromString(p2shaddr).get.script.toProposition(true)
val bs = ValueSerializer.serialize(prop)
val bac = ByteArrayConstant(bs)
ErgoTree(16,WrappedArray(IntConstant(1), IntConstant(0), IntConstant(1), IntConstant(0), IntConstant(0), LongConstant(1), LongConstant(0), LongConstant(1000), IntConstant(2), ConstantNode(Coll(-62,41,-52,18,-61,-101,120,-5,-103,-33,58,-128,51,40,-14,-71,-74,-25,-2,66,-80,-46,95,54,-45,-4,9,32,121,-50,-116,1),Coll[SByte$])),Right(BlockValue(WrappedArray(ValDef(1,WrappedArray(),MethodCall(Self$(167),SMethod(SBox,tokens,(SBox) => Coll[(Coll[SByte$],SLong$)],8,FixedCost(JitCost(15)),MethodIRInfo(Some(<function1>),None,None),Some(OperationInfo(Some(PropertyCall$(219)),Secondary tokens,ArrayBuffer(ArgInfo(this,this instance)))),None),WrappedArray(),Map())), ValDef(2,WrappedArray(),ByIndex(ValUse(1,Coll[(Coll[SByte$],SLong$)]),ConstantPlaceholder(0,SInt$),None)), ValDef(3,WrappedArray(),SelectField(ValUse(2,(Coll[SByte$],SLong$)),2)), ValDef(4,WrappedArray(),ByIndex(Outputs$(165),ConstantPlaceholder(1,SInt$),None)), ValDef(5,WrappedArray(),MethodCall(ValUse(4,SBox),SMethod(SBox,tokens,(SBox) => Coll[(Coll[SByte$],SL
{
// ===== Contract Information ===== //
// Name: Phoenix HodlCoin Bank
// Description: Contract for the bank box of the HodlCoin protocol.
// Version: 1.0.0
// Author: Luca D'Angelo (ldgaetano@protonmail.com), MGPai
// ===== Box Contents ===== //
// Tokens
@kushti
kushti / AdaptiveSimulator.scala
Created January 30, 2023 11:41
EIP-37 DAA simulator
package org.ergoplatform.tools
import org.ergoplatform.mining.difficulty.{DifficultyAdjustment, RequiredDifficulty}
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.settings.{Args, ErgoSettings, NetworkType}
import java.util.concurrent.TimeUnit
import scala.collection.mutable
import scala.concurrent.duration.FiniteDuration
import scala.util.Random
@kushti
kushti / FromSnapshot.scala
Created January 8, 2023 19:19
fromSnapshot functions removed from UtxoState (not used now)
def fromSnapshot(prover: BatchAVLProver[Digest32, HF],
settings: ErgoSettings) = {
val stateDir = ErgoState.stateDir(settings)
stateDir.mkdirs()
val constants = StateConstants(settings)
val store = new LDBVersionedStore(stateDir, initialKeepVersions = constants.keepVersions)
val version = store.get(bestVersionKey).map(w => bytesToVersion(w))
.getOrElse(ErgoState.genesisStateVersion)
val persistentProver: PersistentBatchAVLProver[Digest32, HF] = {