Skip to content

Commit

Permalink
Merge pull request #159 from xssnick/master
Browse files Browse the repository at this point in the history
Update with v1.8.8
  • Loading branch information
xssnick authored Dec 7, 2023
2 parents 6860e0c + 426b2cd commit a402511
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
4 changes: 2 additions & 2 deletions example/wallet-cold-alike/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func main() {
if balance.Nano().Uint64() >= 3000000 {
addr := address.MustParseAddr("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N")

log.Println("sending transaction and waiting for confirmation...")
log.Println("sending transaction...")

// default message ttl is 3 minutes, it is time during which you can send it to blockchain
// if you need to set longer TTL, you could use this method
Expand Down Expand Up @@ -82,7 +82,7 @@ func main() {
return
}

log.Println("transaction sent")
log.Println("transaction sent, we are not waiting for confirmation")

return
}
Expand Down
3 changes: 2 additions & 1 deletion example/wallet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func main() {
log.Println("sending transaction and waiting for confirmation...")

// if destination wallet is not initialized (or you don't care)
// you should set bounce to true to not get money back
// you should set bounce to false to not get money back.
// If bounce is true, money will be returned in case of not initialized destination wallet or smart-contract error
bounce := false

transfer, err := w.BuildTransfer(addr, tlb.MustFromTON("0.003"), bounce, "Hello from tonutils-go!")
Expand Down
13 changes: 9 additions & 4 deletions ton/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,14 @@ func (c *APIClient) GetBlockShardsInfo(ctx context.Context, master *BlockIDExt)
}
}

return LoadShardsFromHashes(inf.ShardHashes)
return LoadShardsFromHashes(inf.ShardHashes, false)
case LSError:
return nil, t
}
return nil, errUnexpectedResponse(resp)
}

func LoadShardsFromHashes(shardHashes *cell.Dictionary) (shards []*BlockIDExt, err error) {
func LoadShardsFromHashes(shardHashes *cell.Dictionary, skipPruned bool) (shards []*BlockIDExt, err error) {
if shardHashes == nil {
return []*BlockIDExt{}, nil
}
Expand All @@ -473,12 +473,17 @@ func LoadShardsFromHashes(shardHashes *cell.Dictionary) (shards []*BlockIDExt, e
}

var binTree tlb.BinTree
err = binTree.LoadFromCell(binTreeRef)
if err != nil {
if err = tlb.LoadFromCellAsProof(&binTree, binTreeRef); err != nil {
return nil, fmt.Errorf("load BinTree err: %w", err)
}

for _, bk := range binTree.All() {
if skipPruned && bk.Value.GetType() != cell.OrdinaryCellType {
// in case of split we have list with only needed shard,
// and pruned branch for others.
continue
}

loader := bk.Value.BeginParse()

ab, err := loader.LoadUInt(4)
Expand Down
37 changes: 37 additions & 0 deletions ton/block_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ton

import (
"encoding/hex"
"github.com/xssnick/tonutils-go/tvm/cell"
"testing"
)

func TestLoadShardsFromHashes(t *testing.T) {
data, err := hex.DecodeString("b5ee9c724102090100010b000103d040012201c002032201c00405284801012610bab489d8faa8c9dfaa65e8281895cfc66591881d1d5351574975ce386f2b00032201c00607284801013ca47d35fc14db1a5f2e33f74cf3e833974de0fea9f49759ea84d2522124d12b000201eb50134ea4181081ebe000013951e6cc660000013951e6cc6608c7a91c9653b122d1e49487ecc663e5bb59d8974d6ddd03a4c5cdd7c325498e92b103dc863224263143d3b59124e2a4bce36ddd4ce7f4c43ae0476430da34061280003e18b880000000000000001080fd6b2b80b3cecae02d12000000c90828480101c2256a5539b179d8831bcbfb692dc691ba4c604a72a60ff375306e2b29764a4900010013407735940203b9aca0202872d22f")
if err != nil {
t.Fatal(err)
}

cl, err := cell.FromBOC(data)
if err != nil {
t.Fatal(err)
}

di, err := cl.BeginParse().ToDict(32)
if err != nil {
t.Fatal(err)
}

gotShards, err := LoadShardsFromHashes(di, true)
if err != nil {
t.Fatal(err)
}
if len(gotShards) != 1 {
t.Fatal("not 1 shard")
}

gotShards, err = LoadShardsFromHashes(di, false)
if err == nil {
t.Fatal("should be err")
}
}
2 changes: 1 addition & 1 deletion ton/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func CheckShardInMasterProof(master *BlockIDExt, shardProof []*cell.Cell, workch
return fmt.Errorf("failed to check proof for mc state extra: %w", err)
}

shards, err := LoadShardsFromHashes(stateExtra.ShardHashes)
shards, err := LoadShardsFromHashes(stateExtra.ShardHashes, true)
if err != nil {
return fmt.Errorf("failed to load shard hashes: %w", err)
}
Expand Down

0 comments on commit a402511

Please sign in to comment.