Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions abi/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,24 @@ func TestDecodeAndEncodeUnknownInMsgBody(t *testing.T) {
t.Fatalf("got different result")
}
}

func TestDecodeAndEncodeHashMap(t *testing.T) {
data := "b5ee9c7241010b0100f4000202c8010a0201620209020120030802012004070201580506004327fd889d4ca5a81250b38cfb489c99475bacacb61c512fac81458a37f66e1b10eff400432002aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac0044d4ff53355555555555555555555555555555555555555555555555555555555555550045bd002c44ea652d4092859c67da44e4ca3add6565b0e2897d640a2c51bfb370d8877fa00045a3cff555555555555555555555555555555555555555555555555555555555555555580045bd5800aa6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab8a1b898e"
boc1, _ := boc.DeserializeBocHex(data)

var x tlb.Hashmap[tlb.Uint16, tlb.MsgAddress]
if err := tlb.Unmarshal(boc1[0], &x); err != nil {
t.Fatalf("Unable to unmarshal: %v", err)
}

boc2 := boc.NewCell()
if err := tlb.Marshal(boc2, x); err != nil {
t.Fatalf("Unable to marshal: %v", err)
}

hs1, _ := boc1[0].HashString()
hs2, _ := boc2.HashString()
if hs1 != hs2 {
t.Fatalf("got different result")
}
}
3 changes: 2 additions & 1 deletion boc/bitString.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,11 @@ func (s *BitString) ReadBigUint(bitLen int) (*big.Int, error) {
}
b = []byte{byte(firstByte)}
}
b, err = s.ReadBytes(bitLen / 8)
normalizeB, err := s.ReadBytes(bitLen / 8)
if err != nil {
return nil, err
}
b = append(b, normalizeB...)
num.SetBytes(b)
return num, nil
}
Expand Down
16 changes: 16 additions & 0 deletions boc/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (c *Cell) BitSize() int {
func (c *Cell) Hash() ([]byte, error) {
return c.hash(map[*Cell]*immutableCell{})
}

func (c *Cell) Hash256() ([32]byte, error) {
b, err := c.hash(map[*Cell]*immutableCell{})
if err != nil {
Expand Down Expand Up @@ -340,6 +341,21 @@ func (c *Cell) CopyRemaining() *Cell {
return c2
}

func (c *Cell) CopyCell() *Cell {
if c == nil {
return nil
}
c2 := NewCellWithBits(c.RawBitString())
for _, ref := range c.Refs() {
refCopy := ref.CopyCell()
if err := c2.AddRef(refCopy); err != nil {
// this should never happen but anyway
panic(err)
}
}
return c2
}

func (c *Cell) WriteBytes(b []byte) error {
return c.bits.WriteBytes(b)
}
Expand Down
75 changes: 75 additions & 0 deletions examples/tolk/payload-unmarshal/abi/jetton_wallet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"contractName": "Jetton",
"declarations": [
{
"kind": "Struct",
"name": "Transfer",
"prefix": {
"prefixStr": "0x0f8a7ea5",
"prefixLen": 32
},
"fields": [
{
"name": "queryId",
"ty": {
"kind": "uintN",
"n": 64
}
},
{
"name": "amount",
"ty": {
"kind": "coins"
}
},
{
"name": "destination",
"ty": {
"kind": "address"
}
},
{
"name": "responseDestination",
"ty": {
"kind": "address"
}
},
{
"name": "customPayload",
"ty": {
"kind": "nullable",
"inner": {
"kind": "cell"
}
}
},
{
"name": "forwardAmount",
"ty": {
"kind": "coins"
}
},
{
"name": "forwardPayload",
"isPayload": true,
"ty": {
"kind": "remaining"
}
}
]
}
],
"incomingMessages": [],
"outgoingMessages": [],
"emittedEvents": [],
"storage": {
"storageTy": {
"kind": "nullLiteral"
}
},
"getMethods": [],
"thrownErrors": [],
"compilerName": "tolk",
"compilerVersion": "1.2.0",
"codeBoc64": "te6ccgEBAgEAFQABFP8A9KQT9LzyyAsBAAzTMPiR8kA="
}
156 changes: 156 additions & 0 deletions examples/tolk/payload-unmarshal/abi/swap_coffee.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"contractName": "Test",
"declarations": [
{
"kind": "Struct",
"name": "CoffeeCrossDexResend",
"prefix": {
"prefixStr": "0x4ee9b106",
"prefixLen": 32
},
"fields": [
{
"name": "next",
"isPayload": true,
"ty": {
"kind": "cell"
}
}
]
},
{
"kind": "Struct",
"name": "CoffeeSwap",
"prefix": {
"prefixStr": "0xc0ffee10",
"prefixLen": 32
},
"fields": [
{
"name": "step",
"ty": {
"kind": "StructRef",
"structName": "CoffeeSwapStepParams"
}
},
{
"name": "params",
"ty": {
"kind": "cellOf",
"inner": {
"kind": "StructRef",
"structName": "CoffeeSwapParams"
}
}
}
]
},
{
"kind": "Struct",
"name": "CoffeeSwapStepParams",
"fields": [
{
"name": "poolAddressHash",
"ty": {
"kind": "uintN",
"n": 256
}
},
{
"name": "minOutputAmount",
"ty": {
"kind": "coins"
}
},
{
"name": "next",
"ty": {
"kind": "nullable",
"inner": {
"kind": "cellOf",
"inner": {
"kind": "StructRef",
"structName": "CoffeeSwapStepParams"
}
}
}
}
]
},
{
"kind": "Struct",
"name": "CoffeeSwapParams",
"fields": [
{
"name": "deadline",
"ty": {
"kind": "uintN",
"n": 32
}
},
{
"name": "recipient",
"ty": {
"kind": "address"
}
},
{
"name": "referral",
"ty": {
"kind": "addressOpt"
}
},
{
"name": "notificationData",
"ty": {
"kind": "nullable",
"inner": {
"kind": "cellOf",
"inner": {
"kind": "StructRef",
"structName": "CoffeeNotificationData"
}
}
}
}
]
},
{
"kind": "Struct",
"name": "CoffeeNotificationData",
"fields": [
{
"name": "reciever",
"ty": {
"kind": "address"
}
},
{
"name": "fwdGas",
"ty": {
"kind": "coins"
}
},
{
"name": "payload",
"ty": {
"kind": "cell"
}
}
]
}
],
"incomingMessages": [],
"outgoingMessages": [],
"emittedEvents": [],
"storage": {
"storageTy": {
"kind": "nullLiteral"
}
},
"getMethods": [],
"thrownErrors": [],
"compilerName": "tolk",
"compilerVersion": "1.2.0",
"codeBoc64": "te6ccgEBAgEAFQABFP8A9KQT9LzyyAsBAAzTMPiR8kA="
}
Loading
Loading