Skip to content

Commit

Permalink
fix: Fixed examples that used CryptoTransferTransaction to use new Tr…
Browse files Browse the repository at this point in the history
…ansferTransaction
  • Loading branch information
andrix10 authored and janaakhterov committed Nov 9, 2020
1 parent 7c4a6a9 commit 16e708f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
6 changes: 3 additions & 3 deletions examples/create_account_with_threshold_keys/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ func main() {

fmt.Printf("account = %v\n", newAccountID)

transferTx, err := hedera.NewCryptoTransferTransaction().
transferTx, err := hedera.NewTransferTransaction().
SetTransactionID(hedera.TransactionIDGenerate(newAccountID)).
SetNodeAccountIDs([]hedera.AccountID{transactionResponse.NodeID}).
AddSender(newAccountID, hedera.HbarFrom(5, hedera.HbarUnits.Hbar)).
AddRecipient(client.GetOperatorID(), hedera.HbarFrom(5, hedera.HbarUnits.Hbar)).
AddHbarSender(newAccountID, hedera.HbarFrom(5, hedera.HbarUnits.Hbar)).
AddHbarRecipient(client.GetOperatorID(), hedera.HbarFrom(5, hedera.HbarUnits.Hbar)).
FreezeWith(client)

if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions examples/multi_app_transfer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func main() {
txID := hedera.TransactionIDGenerate(operatorAccountID)

// The following steps are required for manually signing
transaction, err := hedera.NewCryptoTransferTransaction().
transaction, err := hedera.NewTransferTransaction().
// 1. Manually set the transaction ID
SetTransactionID(txID).
// 2. Add your sender and amount to be send
AddSender(operatorAccountID, hedera.NewHbar(1)).
AddHbarTransfer(operatorAccountID, hedera.NewHbar(1)).
// 3. add the recipient(s) and amount to be received
AddRecipient(recipientAccountID, hedera.NewHbar(1)).
AddHbarTransfer(recipientAccountID, hedera.NewHbar(-1)).
SetTransactionMemo("go sdk example multi_app_transfer/main.go").
// 4. build the transaction using the client that does not have a set operator
FreezeWith(client)
Expand Down Expand Up @@ -61,7 +61,7 @@ func main() {
fmt.Printf("received bytes for signed transaction \n%v\n", signedTxBytes)

// unmarshal your bytes into the signed transaction
var signedTx hedera.CryptoTransferTransaction
var signedTx hedera.TransferTransaction
err = signedTx.UnmarshalBinary(signedTxBytes)

if err != nil {
Expand Down Expand Up @@ -98,7 +98,7 @@ func signingService(txBytes []byte) ([]byte, error) {
}

// unmarshal the unsigned transaction's bytes
var unsignedTx hedera.CryptoTransferTransaction
var unsignedTx hedera.TransferTransaction
err = unsignedTx.UnmarshalBinary(txBytes)

if err != nil {
Expand Down
1 change: 1 addition & 0 deletions examples/transfer_tokens/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func main() {
transactionResponse, err = hedera.NewTokenCreateTransaction().
SetName("ffff").
SetSymbol("F").
SetMaxTransactionFee(hedera.NewHbar(1000)).
SetNodeAccountIDs([]hedera.AccountID{transactionResponse.NodeID}).
SetDecimals(3).
SetInitialSupply(1000000).
Expand Down
10 changes: 10 additions & 0 deletions transfer_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ func (transaction *TransferTransaction) AddHbarTransfer(accountID AccountID, amo
return transaction
}

func (transaction *TransferTransaction) AddHbarSender(accountID AccountID, amount Hbar) *TransferTransaction {
transaction.requireNotFrozen()
return transaction.AddHbarTransfer(accountID, amount.negated())
}

func (transaction *TransferTransaction) AddHbarRecipient(accountID AccountID, amount Hbar) *TransferTransaction {
transaction.requireNotFrozen()
return transaction.AddHbarTransfer(accountID, amount)
}

func (transaction *TransferTransaction) AddTokenTransfer(tokenID TokenID, accountID AccountID, value int64) *TransferTransaction {
transaction.requireNotFrozen()

Expand Down

0 comments on commit 16e708f

Please sign in to comment.