Skip to content

Commit

Permalink
UTXO adjustments (#77)
Browse files Browse the repository at this point in the history
* [TX] add empty asset validation

* Revert "[TX] add empty asset validation"

This reverts commit 66e99cc

* [TX] return only user's address for delegation related txs
  • Loading branch information
covain authored Jul 6, 2021
1 parent 4f45dc1 commit 243e4d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
10 changes: 8 additions & 2 deletions types/v1/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ func cleanMemo(memo string) string {

func (t *Tx) GetAddresses() []string {
addresses := make([]string, 0)
switch t.Metadata.(type) {
case *Transfer, *ContractCall:
switch t.Type {
case TxTransfer:
if len(t.Inputs) > 0 || len(t.Outputs) > 0 {
uniqueAddresses := make(map[string]struct{})
for _, input := range t.Inputs {
Expand All @@ -257,6 +257,12 @@ func (t *Tx) GetAddresses() []string {
}

return append(addresses, t.From, t.To)
case TxContractCall:
return append(addresses, t.From, t.To)
case TxStakeDelegate, TxStakeRedelegate:
return append(addresses, t.From)
case TxStakeUndelegate, TxStakeClaimRewards:
return append(addresses, t.To)
default:
return addresses
}
Expand Down
22 changes: 19 additions & 3 deletions types/v1/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func TestTx_GetAddresses(t *testing.T) {
{
name: "transfer",
tx: Tx{
Type: TxTransfer,
From: "from",
To: "to",
Metadata: &Transfer{},
Expand All @@ -138,15 +139,27 @@ func TestTx_GetAddresses(t *testing.T) {
{
name: "delegation",
tx: Tx{
Type: TxStakeDelegate,
From: "from",
To: "to",
Metadata: &Transfer{},
},
expected: []string{"from", "to"},
expected: []string{"from"},
},
{
name: "undelegation",
tx: Tx{
Type: TxStakeUndelegate,
From: "from",
To: "to",
Metadata: &Transfer{},
},
expected: []string{"to"},
},
{
name: "contract_call",
tx: Tx{
Type: TxContractCall,
From: "from",
To: "to",
Metadata: &ContractCall{},
Expand All @@ -156,6 +169,7 @@ func TestTx_GetAddresses(t *testing.T) {
{
name: "any_action",
tx: Tx{
Type: TxTransfer,
From: "from",
To: "to",
Metadata: &Transfer{},
Expand All @@ -165,11 +179,12 @@ func TestTx_GetAddresses(t *testing.T) {
{
name: "redelegation",
tx: Tx{
From: "from_validator",
Type: TxStakeRedelegate,
From: "from",
To: "to_validator",
Metadata: &Transfer{},
},
expected: []string{"from_validator", "to_validator"},
expected: []string{"from"},
},
{
name: "undefined",
Expand All @@ -182,6 +197,7 @@ func TestTx_GetAddresses(t *testing.T) {
{
name: "utxo",
tx: Tx{
Type: TxTransfer,
From: "from_utxo",
To: "from_utxo",
Inputs: []TxOutput{{Address: "from_utxo"}},
Expand Down

0 comments on commit 243e4d0

Please sign in to comment.