parameter (pair %decodeBigMapDiff (bytes %key) (option (bytes %value))) # value can be null, so we made it optional storage (map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))) BEGIN %decodeBigMapDiff (Pair 0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3 (Some 0x05070700ac9a010200000000)) {} # empty map DUP ; DIP { CDR @storage } ; # save storage on the bottom of the stack CAR @parameter DUP ; CAR @key # first let's check the key UNPACK (pair string address) ; # trying to unpack big map key (they can be of different types underneath) ASSERT_SOME DUP ; CAR @label PUSH string "ledger" ; ASSERT_CMPEQ ; # make sure it's balance data DUMP CDR @holder ; SWAP ; CDR @value ; ASSERT_SOME # actually we need to handle cases when a key is removed from big_map, will do later UNPACK (pair nat (map address nat)) ; ASSERT_SOME # here we can fail, since we know exactly how data is packed CAR @balance PUSH @symbol string "TZBTC" ; # adding metadata PUSH @decimals nat 8 ; DUMP PAIR ; SWAP ; PAIR ; SOME ; SWAP ; UPDATE # writing to the storage NIL operation ; PAIR ; COMMIT parameter (pair %decodeBigMapDiff (bytes %key) (option (bytes %value))) ; storage (map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))) ; code { DUP ; CAR ; DIP { CDR } ; DUP ; CAR ; UNPACK (pair string address) ; IF_SOME { DUP ; CAR ; PUSH string "ledger" ; IFCMPEQ { CDR @holder ; SWAP ; CDR ; IF_SOME { UNPACK (pair nat (map address nat)) ; ASSERT_SOME ; CAR @balance ; } { PUSH @balance nat 0; } ; PUSH @symbol string "TZBTC" ; PUSH @decimals nat 8 ; PAIR ; SWAP ; PAIR ; SOME ; SWAP ; UPDATE } { DROP 2 } ; } { DROP } ; NIL operation ; PAIR ; } DEBUG False RUN %decodeBigMapDiff (Pair 0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3 (Some 0x05070700ac9a010200000000)) {} RUN %decodeBigMapDiff (Pair 0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3 None) {} RUN %decodeBigMapDiff (Pair 0xdeadbeef None) {}