From 081ae2770dd129e81610f07a41420e218a4ca25d Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Thu, 14 Mar 2019 11:00:58 -0400 Subject: [PATCH] add support for 'close remainder to' field --- CHANGELOG.md | 4 ++++ README.md | 2 +- crypto/crypto_test.go | 2 +- examples/gen-addresses/main.go | 2 +- transaction/transaction.go | 16 +++++++++++++--- types/transaction.go | 6 ++++++ 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a26b66fb..a5cb9670 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 3c28d733..a173e3c9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go index 3d971a99..c1cc2b97 100644 --- a/crypto/crypto_test.go +++ b/crypto/crypto_test.go @@ -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 diff --git a/examples/gen-addresses/main.go b/examples/gen-addresses/main.go index 904337a0..e70bdf29 100644 --- a/examples/gen-addresses/main.go +++ b/examples/gen-addresses/main.go @@ -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 diff --git a/transaction/transaction.go b/transaction/transaction.go index 55952e96..b0fb02de 100644 --- a/transaction/transaction.go +++ b/transaction/transaction.go @@ -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 { @@ -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, @@ -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 diff --git a/types/transaction.go b/types/transaction.go index 2f5fa42b..b143eee7 100644 --- a/types/transaction.go +++ b/types/transaction.go @@ -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.