Skip to content

Commit

Permalink
Fix: NFT
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Mar 15, 2021
1 parent edc63d1 commit 163be9f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/api/handlers/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (ctx *Context) prepareMempoolOperation(item tzkt.MempoolOperation, network
return &op
}

if bcd.IsContract(op.Destination) && op.Protocol != "" {
if bcd.IsContract(op.Destination) && op.Protocol != "" && op.Status == consts.Pending {
if len(item.Body.Parameters) > 0 {
_ = ctx.buildOperationParameters(item.Body.Parameters, &op)
} else {
Expand Down
33 changes: 33 additions & 0 deletions internal/bcd/ast/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1551,3 +1551,36 @@ func TestTypedAst_GetEntrypointsDocs(t *testing.T) {
})
}
}

func TestTypedAst_EqualType(t *testing.T) {
tests := []struct {
name string
typ1 string
typ2 string
want bool
}{
{
name: "NFT",
typ1: `{"prim":"map","args":[{"prim":"nat"},{"prim":"address"}]}`,
typ2: `{"prim":"map","args":[{"prim":"nat"},{"prim":"int"}]}`,
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a, err := NewTypedAstFromString(tt.typ1)
if err != nil {
t.Errorf("NewTypedAstFromString(a) = %v", err)
return
}
b, err := NewTypedAstFromString(tt.typ2)
if err != nil {
t.Errorf("NewTypedAstFromString(b) = %v", err)
return
}
if got := a.EqualType(b); got != tt.want {
t.Errorf("TypedAst.EqualType() = %v, want %v", got, tt.want)
}
})
}
}
9 changes: 8 additions & 1 deletion internal/bcd/ast/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,14 @@ func (d *Default) Compare(second Comparable) (int, error) {

// EqualType -
func (d *Default) EqualType(node Node) bool {
return d.Prim == node.GetPrim()
if d.Prim == node.GetPrim() {
return true
}
second, ok := node.(*Default)
if !ok {
return false
}
return d.ValueKind == second.ValueKind
}

// Equal -
Expand Down
16 changes: 12 additions & 4 deletions internal/parsers/tokenbalance/nft_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,21 @@ func (p NftAsset) Parse(data []byte) ([]TokenBalance, error) {
var address string
switch t := value.(type) {
case *ast.Address:
address = forge.DecodeString(t.Value.(string))
balance.SetInt64(1)
if s, ok := t.Value.(string); ok {
address = forge.DecodeString(s)
balance.SetInt64(1)
} else {
return false, nil
}
case *ast.Option:
if t.IsSome() {
val := t.Type.(*ast.Address)
address = forge.DecodeString(val.Value.(string))
balance.SetInt64(1)
if s, ok := val.Value.(string); ok {
address = forge.DecodeString(s)
balance.SetInt64(1)
} else {
return false, nil
}
}
default:
return false, nil
Expand Down

0 comments on commit 163be9f

Please sign in to comment.