Skip to content

Commit

Permalink
Add delegate/undelegate transaction types and appropriate payloads (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
covain authored Apr 28, 2021
1 parent 5807c37 commit 8a0db43
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 8 additions & 0 deletions types/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func (t *Tx) UnmarshalJSON(data []byte) error {
t.Meta = new(ContractCall)
case TxAnyAction:
t.Meta = new(AnyAction)
case TxDelegation:
t.Meta = new(Delegation)
case TxUndelegation:
t.Meta = new(Undelegation)
default:
return errors.New("unsupported tx type")
}
Expand Down Expand Up @@ -78,6 +82,10 @@ func (t *Tx) MarshalJSON() ([]byte, error) {
t.Type = TxContractCall
case AnyAction, *AnyAction:
t.Type = TxAnyAction
case Delegation, *Delegation:
t.Type = TxDelegation
case Undelegation, *Undelegation:
t.Type = TxUndelegation
default:
return nil, errors.New("unsupported tx metadata")
}
Expand Down
22 changes: 21 additions & 1 deletion types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const (
TxContractCall TransactionType = "contract_call"
TxAnyAction TransactionType = "any_action"
TxMultiCurrencyTransfer TransactionType = "multi_currency_transfer"
TxDelegation TransactionType = "delegation"
TxUndelegation TransactionType = "undelegation"

KeyPlaceOrder KeyType = "place_order"
KeyCancelOrder KeyType = "cancel_order"
Expand Down Expand Up @@ -103,8 +105,8 @@ type (
// TokenTransfers
TokenTransfers []TokenTransfer `json:"token_transfers,omitempty"`
// Meta data object
Memo string `json:"memo"`
Meta interface{} `json:"metadata"`
Memo string `json:"memo"`
}

TxOutput struct {
Expand Down Expand Up @@ -143,6 +145,20 @@ type (
To string `json:"to"`
}

// Delegation describes the blocking of a stacked currency
Delegation struct {
Value Amount `json:"value"`
Symbol string `json:"symbol"`
Decimals uint `json:"decimals"`
}

// Undelegation describes the unblocking of stacked currency
Undelegation struct {
Value Amount `json:"value"`
Symbol string `json:"symbol"`
Decimals uint `json:"decimals"`
}

// CollectibleTransfer describes the transfer of a
// "collectible", unique token.
CollectibleTransfer struct {
Expand Down Expand Up @@ -381,6 +397,10 @@ func (t *Tx) GetTransactionDirection(address string) Direction {
return determineTransactionDirection(address, meta.From, meta.To)
case NativeTokenTransfer:
return determineTransactionDirection(address, meta.From, meta.To)
case Delegation:
return DirectionOutgoing
case Undelegation:
return DirectionIncoming
default:
return determineTransactionDirection(address, t.From, t.To)
}
Expand Down

0 comments on commit 8a0db43

Please sign in to comment.