Skip to content

Commit

Permalink
Wallet V5 & Shard helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
xssnick committed May 18, 2024
1 parent 5943977 commit 9213c8f
Show file tree
Hide file tree
Showing 7 changed files with 576 additions and 6 deletions.
4 changes: 2 additions & 2 deletions example/deploy-nft-collection/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func main() {
msgBody := cell.BeginCell().EndCell()

fmt.Println("Deploying NFT collection contract to mainnet...")
addr, err := w.DeployContract(context.Background(), tlb.MustFromTON("0.02"),
msgBody, getNFTCollectionCode(), getContractData(w.WalletAddress(), w.WalletAddress()), true)
addr, _, _, err := w.DeployContractWaitTransaction(context.Background(), tlb.MustFromTON("0.02"),
msgBody, getNFTCollectionCode(), getContractData(w.WalletAddress(), w.WalletAddress()))
if err != nil {
panic(err)
}
Expand Down
53 changes: 53 additions & 0 deletions tlb/shard.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tlb

import (
"encoding/binary"
"github.com/xssnick/tonutils-go/address"
"github.com/xssnick/tonutils-go/tvm/cell"
)

Expand All @@ -13,6 +15,8 @@ func init() {
Register(ShardStateUnsplit{})
}

type ShardID uint64

type ShardStateUnsplit struct {
_ Magic `tlb:"#9023afe2"`
GlobalID int32 `tlb:"## 32"`
Expand Down Expand Up @@ -146,3 +150,52 @@ type ShardDescB struct {
FeesCollected CurrencyCollection `tlb:"."`
FundsCreated CurrencyCollection `tlb:"."`
}

func (s ShardID) IsSibling(with ShardID) bool {
return (s^with) != 0 && ((s ^ with) == ((s & ShardID(bitsNegate64(uint64(s)))) << 1))
}

func (s ShardID) IsParent(of ShardID) bool {
y := lowerBit64(uint64(s))
return y > 0 && of.GetParent() == s
}

func (s ShardID) GetParent() ShardID {
y := lowerBit64(uint64(s))
return ShardID((uint64(s) - y) | (y << 1))
}

func (s ShardID) GetChild(left bool) ShardID {
y := lowerBit64(uint64(s)) >> 1
if left {
return s - ShardID(y)
}
return s + ShardID(y)
}

func (s ShardID) ContainsAddress(addr *address.Address) bool {
x := lowerBit64(uint64(s))
return ((uint64(s) ^ binary.BigEndian.Uint64(addr.Data())) & (bitsNegate64(x) << 1)) == 0
}

func (s ShardID) IsAncestor(of ShardID) bool {
x := lowerBit64(uint64(s))
y := lowerBit64(uint64(of))
return x >= y && uint64(s^of)&(bitsNegate64(x)<<1) == 0
}

func (s ShardIdent) IsSibling(with ShardIdent) bool {
return s.WorkchainID == with.WorkchainID && ShardID(s.ShardPrefix).IsSibling(ShardID(with.ShardPrefix))
}

func (s ShardIdent) IsAncestor(of ShardIdent) bool {
return s.WorkchainID == of.WorkchainID && ShardID(s.ShardPrefix).IsAncestor(ShardID(of.ShardPrefix))
}

func (s ShardIdent) IsParent(of ShardIdent) bool {
return s.WorkchainID == of.WorkchainID && ShardID(s.ShardPrefix).IsParent(ShardID(of.ShardPrefix))
}

func (s ShardIdent) GetShardID() ShardID {
return ShardID(s.ShardPrefix)
}
Loading

0 comments on commit 9213c8f

Please sign in to comment.