Skip to content

Commit

Permalink
add support for 'close remainder to' field
Browse files Browse the repository at this point in the history
  • Loading branch information
algomaxj committed Mar 14, 2019
1 parent c848079 commit 081ae27
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.0.1
## Added
- SDK released
# 0.0.2
## Added
- Support for "genesis ID" field in transactions
- Support for "close remainder to" field in transactions
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func main() {

// Make transaction
genID := txParams.GenesisID
tx, err := transaction.MakePaymentTxn(fromAddr, toAddr, 1, 100, 300, 400, nil, genID)
tx, err := transaction.MakePaymentTxn(fromAddr, toAddr, 1, 100, 300, 400, nil, "", genID)
if err != nil {
fmt.Printf("Error creating transaction: %s\n", err)
return
Expand Down
2 changes: 1 addition & 1 deletion crypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestSignTransaction(t *testing.T) {
const toAddr = "PU7ZTZJ5GSXET2ZPIWDWDT2TQQEP7WXOGXDQ3ARUCZW6PK7D4ULSE6NYCE"

// Build the unsigned transaction
tx, err := transaction.MakePaymentTxn(fromAddr, toAddr, 1, 1234, 106575, 107575, nil)
tx, err := transaction.MakePaymentTxn(fromAddr, toAddr, 1, 1234, 106575, 107575, nil, "", "")
require.NoError(t, err)

// Decode the secret key for the sender
Expand Down
2 changes: 1 addition & 1 deletion examples/gen-addresses/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func main() {

// Sign a sample transaction using this library, *not* kmd
genID := txParams.GenesisID
tx, err := transaction.MakePaymentTxn(addresses[0], addresses[1], 1, 100, 300, 400, nil, genID)
tx, err := transaction.MakePaymentTxn(addresses[0], addresses[1], 1, 100, 300, 400, nil, "", genID)
if err != nil {
fmt.Printf("Error creating transaction: %s\n", err)
return
Expand Down
16 changes: 13 additions & 3 deletions transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

// MakePaymentTxn constructs a payment transaction using the passed parameters.
// `from` and `to` addresses should be checksummed, human-readable addresses
func MakePaymentTxn(from, to string, fee, amount, firstRound, lastRound uint64, note []byte, genesisID string) (tx types.Transaction, err error) {
func MakePaymentTxn(from, to string, fee, amount, firstRound, lastRound uint64, note []byte, closeRemainderTo, genesisID string) (tx types.Transaction, err error) {
// Decode from address
fromAddr, err := types.DecodeAddress(from)
if err != nil {
Expand All @@ -19,6 +19,15 @@ func MakePaymentTxn(from, to string, fee, amount, firstRound, lastRound uint64,
return
}

// Decode the CloseRemainderTo address, if present
var closeRemainderToAddr types.Address
if closeRemainderTo != "" {
closeRemainderToAddr, err = types.DecodeAddress(closeRemainderTo)
if err != nil {
return
}
}

// Build the transaction
tx = types.Transaction{
Type: types.PaymentTx,
Expand All @@ -31,8 +40,9 @@ func MakePaymentTxn(from, to string, fee, amount, firstRound, lastRound uint64,
GenesisID: genesisID,
},
PaymentTxnFields: types.PaymentTxnFields{
Receiver: toAddr,
Amount: types.Algos(amount),
Receiver: toAddr,
Amount: types.Algos(amount),
CloseRemainderTo: closeRemainderToAddr,
},
}
return
Expand Down
6 changes: 6 additions & 0 deletions types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ type PaymentTxnFields struct {

Receiver Address `codec:"rcv"`
Amount Algos `codec:"amt"`

// When CloseRemainderTo is set, it indicates that the
// transaction is requesting that the account should be
// closed, and all remaining funds be transferred to this
// address.
CloseRemainderTo Address `codec:"close"`
}

// Header captures the fields common to every transaction type.
Expand Down

0 comments on commit 081ae27

Please sign in to comment.