Skip to content

Commit

Permalink
Add new transaction type for NFT token transfer (#86)
Browse files Browse the repository at this point in the history
* Add new transaction type for NFT token transfer

* Update tests
  • Loading branch information
vminkobin authored Dec 21, 2022
1 parent c19bee4 commit e0a6c7e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion types/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func (t *Tx) UnmarshalJSON(data []byte) error {
t.Metadata = new(ContractCall)
case TxSwap:
t.Metadata = new(Swap)
case TxTransferNFT:
t.Metadata = new(TransferNFT)
default:
return fmt.Errorf("unsupported tx type: %s, hash: %s, metadata: %+v", t.Type, t.ID, t.Metadata)
}
Expand All @@ -56,7 +58,7 @@ func (t Tx) MarshalJSON() ([]byte, error) {

// validate metadata type
switch t.Metadata.(type) {
case *Transfer, *ContractCall, *Swap:
case *Transfer, *ContractCall, *Swap, *TransferNFT:
break
default:
return nil, errors.New("unsupported tx metadata")
Expand Down
4 changes: 3 additions & 1 deletion types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ const (
TxStakeUndelegate TransactionType = "stake_undelegate"
TxStakeRedelegate TransactionType = "stake_redelegate"
TxStakeCompound TransactionType = "stake_compound"
TxTransferNFT TransactionType = "transfer_nft"
)

var SupportedTypes = []TransactionType{
TxTransfer, TxSwap, TxContractCall, TxStakeClaimRewards, TxStakeDelegate, TxStakeUndelegate, TxStakeRedelegate,
TxStakeCompound,
TxTransferNFT,
}

// Transaction fields
Expand Down Expand Up @@ -263,7 +265,7 @@ func cleanMemo(memo string) string {
func (t *Tx) GetAddresses() []string {
addresses := make([]string, 0)
switch t.Type {
case TxTransfer:
case TxTransfer, TxTransferNFT:
if len(t.Inputs) > 0 || len(t.Outputs) > 0 {
uniqueAddresses := make(map[string]struct{})
for _, input := range t.Inputs {
Expand Down
10 changes: 10 additions & 0 deletions types/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ func TestTx_GetAddresses(t *testing.T) {
},
expected: []string{"from", "to"},
},
{
name: "transfer_nft",
tx: Tx{
Type: TxTransferNFT,
From: "from",
To: "to",
Metadata: &TransferNFT{},
},
expected: []string{"from", "to"},
},
{
name: "delegation",
tx: Tx{
Expand Down

0 comments on commit e0a6c7e

Please sign in to comment.