Skip to content

Commit

Permalink
Merge pull request #151 from xssnick/dev-v187
Browse files Browse the repository at this point in the history
Improvements and fixes
  • Loading branch information
xssnick authored Dec 5, 2023
2 parents 6f038ab + d24104a commit d7c16c3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img align="right" width="425px" src="https://github.com/xssnick/props/blob/master/logoimg.png?raw=true">

[![Based on TON][ton-svg]][ton]
![Coverage](https://img.shields.io/badge/Coverage-73.3%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-73.4%25-brightgreen)

Golang library for interacting with TON blockchain.

Expand Down
2 changes: 1 addition & 1 deletion adnl/rldp/http/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func getDNSResolver() *dns.Client {
}

// initialize ton api lite connection wrapper
api := ton.NewAPIClient(client)
api := ton.NewAPIClient(client).WithRetry()

// get root dns address from network config
root, err := dns.RootContractAddr(api)
Expand Down
5 changes: 5 additions & 0 deletions liteclient/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ func (c *ConnectionPool) queryWithBalancer(req *ADNLRequest) (string, error) {
return "", ErrNoActiveConnections
}

if reqNode == nil {
// no active nodes in list
return "", ErrNoActiveConnections
}

host, err := reqNode.queryAdnl(req.QueryID, req.Data)
if err != nil {
if !errors.Is(err, NetworkErr{}) {
Expand Down
4 changes: 4 additions & 0 deletions tvm/cell/cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ func TestBOCBomb(t *testing.T) {
if !bytes.Equal(c.Hash(), hash) {
t.Fatal("incorrect hash", hex.EncodeToString(c.Hash()), hex.EncodeToString(hash))
}

if len(c.ToBOCWithFlags(false)) != len(boc) {
t.Fatal("len", len(c.ToBOC()), len(boc))
}
}

func TestCell_TxWithMerkleBody(t *testing.T) {
Expand Down
31 changes: 28 additions & 3 deletions tvm/cell/flattenIndex.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ func flattenIndex(cells []*Cell) ([]*idxItem, map[string]*idxItem) {
for len(cells) > 0 {
next := make([]*Cell, 0, len(cells)*4)
for _, p := range cells {
hash := string(p.Hash())

if _, ok := index[hash]; ok {
continue
}

// move cell forward in boc, because behind reference is not allowed
index[string(p.Hash())] = &idxItem{
index: idx,
index[hash] = &idxItem{
cell: p,
index: idx,
}
idx++

next = append(next, p.refs...)
}
cells = next
Expand All @@ -33,6 +38,26 @@ func flattenIndex(cells []*Cell) ([]*idxItem, map[string]*idxItem) {
idxSlice = append(idxSlice, id)
}

for verifyOrder := true; verifyOrder; {
verifyOrder = false

for _, id := range idxSlice {
for _, ref := range id.cell.refs {
idRef := index[string(ref.Hash())]

if idRef.index < id.index {
// if we found that ref index is behind parent,
// move ref index forward
idRef.index = idx
idx++

// we changed index, so we need to verify order again
verifyOrder = true
}
}
}
}

sort.Slice(idxSlice, func(i, j int) bool {
return idxSlice[i].index < idxSlice[j].index
})
Expand Down

0 comments on commit d7c16c3

Please sign in to comment.