Skip to content

Commit

Permalink
Merge pull request #166 from xssnick/dev-v189
Browse files Browse the repository at this point in the history
Fixed block header proof parse with pruned after merge part
  • Loading branch information
xssnick authored Jan 13, 2024
2 parents 426b2cd + 0b49db0 commit 8ce75d2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 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.4%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-73.3%25-brightgreen)

Golang library for interacting with TON blockchain.

Expand Down
20 changes: 13 additions & 7 deletions tlb/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ func (h *BlockHeader) LoadFromCell(loader *cell.Slice) error {
var infoPart blockInfoPart
err := LoadFromCell(&infoPart, loader)
if err != nil {
return err
return fmt.Errorf("failed to load blockInfoPart: %w", err)
}
h.blockInfoPart = infoPart

if infoPart.Flags&1 == 1 {
var globalVer GlobalVersion
err = LoadFromCell(&globalVer, loader)
if err != nil {
return err
return fmt.Errorf("failed to load GlobalVersion: %w", err)
}
h.GenSoftware = &globalVer
}
Expand All @@ -163,29 +163,29 @@ func (h *BlockHeader) LoadFromCell(loader *cell.Slice) error {
}
err = LoadFromCell(&masterRef, l)
if err != nil {
return err
return fmt.Errorf("failed to load ExtBlkRef: %w", err)
}
h.MasterRef = &masterRef
}

l, err := loader.LoadRef()
if err != nil {
return err
return fmt.Errorf("failed to load ref for after merge: %w", err)
}
prevRef, err := loadBlkPrevInfo(l, infoPart.AfterMerge)
if err != nil {
return err
return fmt.Errorf("failed to loadBlkPrevInfo for after merge: %w", err)
}
h.PrevRef = *prevRef

if infoPart.VertSeqnoIncr {
l, err := loader.LoadRef()
if err != nil {
return err
return fmt.Errorf("failed to load ref for vert incr: %w", err)
}
prevVertRef, err := loadBlkPrevInfo(l, false)
if err != nil {
return err
return fmt.Errorf("failed to loadBlkPrevInfo for prev vert ref: %w", err)
}
h.PrevVertRef = prevVertRef
}
Expand All @@ -195,6 +195,12 @@ func (h *BlockHeader) LoadFromCell(loader *cell.Slice) error {
func loadBlkPrevInfo(loader *cell.Slice, afterMerge bool) (*BlkPrevInfo, error) {
var res BlkPrevInfo

if loader.IsSpecial() {
// TODO: rewrite BlockHeader to pure tlb loader
// if it is a proof we skip load
return &res, nil
}

if !afterMerge {
var blkRef ExtBlkRef
err := LoadFromCell(&blkRef, loader)
Expand Down
4 changes: 4 additions & 0 deletions tlb/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ func (s *Stack) parseValue(slice *cell.Slice) (any, error) {
}
}

if root.RefsNum() == 0 {
return nil
}

ref, err := root.LoadRef()
if err != nil {
return fmt.Errorf("failed to load tuple's %d ref, err: %w", i, err)
Expand Down
9 changes: 6 additions & 3 deletions ton/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ func TestAPIClient_SubscribeOnTransactions(t *testing.T) {
defer cancel()
ctx := api.Client().StickyContext(_ctx)

addr := address.MustParseAddr("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N")
addr := address.MustParseAddr("Ef8zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzM0vF")

b, err := api.CurrentMasterchainInfo(ctx)
if err != nil {
Expand All @@ -672,7 +672,7 @@ func TestAPIClient_SubscribeOnTransactions(t *testing.T) {
t.Fatal("get acc err:", err.Error())
return
}
initLT := acc.LastTxLT - 600000000000
initLT := acc.LastTxLT - 10
log.Println(initLT)
lastLT := initLT

Expand All @@ -682,16 +682,19 @@ func TestAPIClient_SubscribeOnTransactions(t *testing.T) {
ch := make(chan *tlb.Transaction)
go api.SubscribeOnTransactions(ctx, addr, lastLT, ch)

gotTx := false
for tx := range ch {
if lastLT > tx.LT {
t.Fatal("incorrect tx order")
}
lastLT = tx.LT

gotTx = true
println(tx.Now, tx.String())
cancel()
}

if lastLT == initLT {
if !gotTx {
t.Fatal("no transactions")
}
}
Expand Down
4 changes: 4 additions & 0 deletions tvm/cell/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ func (c *Slice) LoadBinarySnake() ([]byte, error) {
return data, nil
}

func (c *Slice) IsSpecial() bool {
return c.special
}

func (c *Slice) BitsLeft() uint {
return c.bitsSz - c.loadedSz
}
Expand Down

0 comments on commit 8ce75d2

Please sign in to comment.