Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Upgrade stellar SDK dependency to 'horizonclient-v3.0.0' tag from ste…
Browse files Browse the repository at this point in the history
…llar/go (closes #412) (#413)

* 1 - submitFilter.go: horizon.Offer -> hProtocol.Offer

* 2 - glide files to upgrade stellar/go dependency to 'horizonclient-v3.0.0'

* 3 - upgrade SignWithSeed function to work with txnbuild v3

* 4 - set new field in txnbuild.Transaction IncrementSequenceNum=true and provide network at signing time

* 5 - remove txnbuild.DeleteOfferOp2

* 6 - remove hProtocol.OfferBase

* 7 - upgrade usage of txnbuild package

* 8 - fix usage of tx via new sdk API changes

* 9 - fix getMaxFee based on updated SDK API

* 10 - autogenerate_bot.go has an upgraded usage of the new txnbuild API

* 11 - upsert_bot_config.go has an upgraded usage of the new txnbuild API
  • Loading branch information
nikhilsaraf authored May 1, 2020
1 parent 2081ad9 commit 9884a04
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 116 deletions.
96 changes: 64 additions & 32 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import:
- package: github.com/spf13/pflag
version: v1.0.0
- package: github.com/stellar/go
repo: https://github.com/nikhilsaraf/go.git
version: horizonclient-v2.0.0/3_fix_txnbuild_delete_offer_op
version: horizonclient-v3.0.0
subpackages:
- build
- clients/horizonclient
Expand Down
37 changes: 22 additions & 15 deletions gui/backend/autogenerate_bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *APIServer) autogenerateBot(w http.ResponseWriter, r *http.Request) {
func (s *APIServer) setupAccount(address string, signer string, botName string) error {
fundedAccount, e := s.checkFundAccount(address, botName)
if e != nil {
return fmt.Errorf("error checking and funding account: %s\n", e)
return fmt.Errorf("error checking and funding account: %s", e)
}

var txOps []txnbuild.Operation
Expand All @@ -117,39 +117,46 @@ func (s *APIServer) setupAccount(address string, signer string, botName string)
}
txOps = append(txOps, &paymentOp)

tx := txnbuild.Transaction{
SourceAccount: fundedAccount,
Operations: txOps,
Timebounds: txnbuild.NewInfiniteTimeout(),
Network: network.TestNetworkPassphrase,
BaseFee: 100,
}
e = tx.Build()
tx, e := txnbuild.NewTransaction(
txnbuild.TransactionParams{
SourceAccount: fundedAccount,
Operations: txOps,
Timebounds: txnbuild.NewInfiniteTimeout(),
BaseFee: 100,
// If IncrementSequenceNum is true, NewTransaction() will call `sourceAccount.IncrementSequenceNumber()`
// to obtain the sequence number for the transaction.
// If IncrementSequenceNum is false, NewTransaction() will call `sourceAccount.GetSequenceNumber()`
// to obtain the sequence number for the transaction.
// leaving as true since that's what it was in the old sdk so we want to maintain backward compatibility and we
// need to increment the seq number on the account somewhere to use the next seq num
IncrementSequenceNum: true,
},
)
if e != nil {
return fmt.Errorf("cannot create trustline transaction for account %s for bot '%s': %s\n", address, botName, e)
return fmt.Errorf("cannot make transaction to create trustline transaction for account %s for bot '%s': %s", address, botName, e)
}

for _, s := range []string{signer, issuerSeed} {
kp, e := keypair.Parse(s)
if e != nil {
return fmt.Errorf("cannot parse seed %s required for signing: %s\n", s, e)
return fmt.Errorf("cannot parse seed %s required for signing: %s", s, e)
}

e = tx.Sign(kp.(*keypair.Full))
tx, e = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
if e != nil {
return fmt.Errorf("cannot sign trustline transaction for account %s for bot '%s': %s\n", address, botName, e)
return fmt.Errorf("cannot sign trustline transaction for account %s for bot '%s': %s", address, botName, e)
}
}

txn64, e := tx.Base64()
if e != nil {
return fmt.Errorf("cannot convert trustline transaction to base64 for account %s for bot '%s': %s\n", address, botName, e)
return fmt.Errorf("cannot convert trustline transaction to base64 for account %s for bot '%s': %s", address, botName, e)
}

client := s.apiTestNet
resp, e := client.SubmitTransactionXDR(txn64)
if e != nil {
return fmt.Errorf("error submitting change trust transaction for address %s for bot '%s': %s\n", address, botName, e)
return fmt.Errorf("error submitting change trust transaction for address %s for bot '%s': %s", address, botName, e)
}

log.Printf("successfully added trustline for address %s for bot '%s': %v\n", address, botName, resp)
Expand Down
37 changes: 22 additions & 15 deletions gui/backend/upsert_bot_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,31 +302,38 @@ func (s *APIServer) checkAddTrustline(account hProtocol.Account, kp keypair.KP,
log.Printf("added trust asset operation to transaction for asset: %+v\n", a)
}

tx := txnbuild.Transaction{
SourceAccount: &account,
Operations: txOps,
Timebounds: txnbuild.NewInfiniteTimeout(),
Network: activeNetwork,
BaseFee: 100,
}
e := tx.Build()
tx, e := txnbuild.NewTransaction(
txnbuild.TransactionParams{
SourceAccount: &account,
Operations: txOps,
Timebounds: txnbuild.NewInfiniteTimeout(),
BaseFee: 100,
// If IncrementSequenceNum is true, NewTransaction() will call `sourceAccount.IncrementSequenceNumber()`
// to obtain the sequence number for the transaction.
// If IncrementSequenceNum is false, NewTransaction() will call `sourceAccount.GetSequenceNumber()`
// to obtain the sequence number for the transaction.
// leaving as true since that's what it was in the old sdk so we want to maintain backward compatibility and we
// need to increment the seq number on the account somewhere to use the next seq num
IncrementSequenceNum: true,
},
)
if e != nil {
return fmt.Errorf("cannot create trustline transaction for account %s for bot '%s': %s\n", address, botName, e)
return fmt.Errorf("cannot make tx to create trustline transaction for account %s for bot '%s': %s", address, botName, e)
}

kpSigner, e := keypair.Parse(traderSeed)
if e != nil {
return fmt.Errorf("cannot parse seed %s required for signing: %s\n", traderSeed, e)
return fmt.Errorf("cannot parse seed %s required for signing: %s", traderSeed, e)
}

e = tx.Sign(kpSigner.(*keypair.Full))
tx, e = tx.Sign(activeNetwork, kpSigner.(*keypair.Full))
if e != nil {
return fmt.Errorf("cannot sign trustline transaction for account %s for bot '%s': %s\n", address, botName, e)
return fmt.Errorf("cannot sign trustline transaction for account %s for bot '%s': %s", address, botName, e)
}

txn64, e := tx.Base64()
if e != nil {
return fmt.Errorf("cannot convert trustline transaction to base64 for account %s for bot '%s': %s\n", address, botName, e)
return fmt.Errorf("cannot convert trustline transaction to base64 for account %s for bot '%s': %s", address, botName, e)
}

txSuccess, e := client.SubmitTransactionXDR(txn64)
Expand All @@ -338,9 +345,9 @@ func (s *APIServer) checkAddTrustline(account hProtocol.Account, kp keypair.KP,
case horizonclient.Error:
herr = &t
default:
return fmt.Errorf("error when submitting change trust transaction for address %s for bot '%s' for assets(%v): %s (%s)\n", address, botName, trustlines, e, txn64)
return fmt.Errorf("error when submitting change trust transaction for address %s for bot '%s' for assets(%v): %s (%s)", address, botName, trustlines, e, txn64)
}
return fmt.Errorf("horizon error when submitting change trust transaction for address %s for bot '%s' for assets(%v): %s (%s)\n", address, botName, trustlines, *herr, txn64)
return fmt.Errorf("horizon error when submitting change trust transaction for address %s for bot '%s' for assets(%v): %s (%s)", address, botName, trustlines, *herr, txn64)
}

log.Printf("tx result of submitting trustline transaction for address %s for bot '%s' for assets(%v): %v (%s)\n", address, botName, trustlines, txSuccess, txn64)
Expand Down
Loading

0 comments on commit 9884a04

Please sign in to comment.