Skip to content

Commit

Permalink
Merge pull request #133 from xssnick/improvements-183
Browse files Browse the repository at this point in the history
Fixed missing decimal after TLB struct load in String coins
  • Loading branch information
xssnick committed Sep 23, 2023
2 parents a1b7609 + 543e14f commit 564da1c
Show file tree
Hide file tree
Showing 4 changed files with 10 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.4%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-73.5%25-brightgreen)

Golang library for interacting with TON blockchain.

Expand Down
1 change: 1 addition & 0 deletions tlb/coins.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func (g *Coins) LoadFromCell(loader *cell.Slice) error {
if err != nil {
return err
}
g.decimals = 9
g.val = coins
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions tlb/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (

type Magic struct{}

type manualLoader interface {
type Unmarshaler interface {
LoadFromCell(loader *cell.Slice) error
}

type manualStore interface {
type Marshaller interface {
ToCell() (*cell.Cell, error)
}

Expand Down Expand Up @@ -53,7 +53,7 @@ func loadFromCell(v any, slice *cell.Slice, skipProofBranches, skipMagic bool) e
}
rv = rv.Elem()

if ld, ok := v.(manualLoader); ok {
if ld, ok := v.(Unmarshaler); ok {
err := ld.LoadFromCell(slice)
if err != nil {
return fmt.Errorf("failed to load from cell for %s, using manual loader, err: %w", rv.Type().Name(), err)
Expand Down Expand Up @@ -392,7 +392,7 @@ func ToCell(v any) (*cell.Cell, error) {
rv = rv.Elem()
}

if ld, ok := v.(manualStore); ok {
if ld, ok := v.(Marshaller); ok {
c, err := ld.ToCell()
if err != nil {
return nil, fmt.Errorf("failed to store to cell for %s, using manual storer, err: %w", reflect.TypeOf(v).PkgPath(), err)
Expand Down
4 changes: 4 additions & 0 deletions tlb/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ func TestLoadFromCell(t *testing.T) {
t.Fatal("coins 700000 not eq")
}

if x.Inside.ValCoins.String() != "0.0007" {
t.Fatal("coins 700000 not eq, got " + x.Inside.ValCoins.String())
}

if x.Part.BigVal.Uint64() != 7126382921832 {
t.Fatal("uint part 7126382921832 not eq")
}
Expand Down

0 comments on commit 564da1c

Please sign in to comment.