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

Upgrade to use stellar/go@horizonclient-v8.0.0 #748

Merged
merged 8 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix myriad of xdr related things that have changed
  • Loading branch information
leighmcculloch committed Nov 4, 2021
commit 669c4085838da9d431b03633a0e70432311898e4
10 changes: 4 additions & 6 deletions api/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"math"

"github.com/stellar/kelp/stellargohorizonclientv300/build"
hProtocol "github.com/stellar/go/protocols/horizon"
"github.com/stellar/go/txnbuild"
"github.com/stellar/go/xdr"
"github.com/stellar/kelp/model"
"github.com/stellar/kelp/stellargohorizonclientv300/build"
)

// ExchangeAPIKey specifies API credentials for an exchange
Expand Down Expand Up @@ -253,8 +253,8 @@ func ConvertOperation2TM(ops []txnbuild.Operation) []build.TransactionMutator {
},
build.OfferID(mso.OfferID),
)
if mso.SourceAccount != nil {
mob.Mutate(build.SourceAccount{AddressOrSeed: mso.SourceAccount.GetAccountID()})
if mso.SourceAccount != "" {
mob.Mutate(build.SourceAccount{AddressOrSeed: mso.SourceAccount})
}
} else {
panic(fmt.Sprintf("could not convert txnbuild.Operation to build.TransactionMutator: %v\n", o))
Expand Down Expand Up @@ -303,9 +303,7 @@ func convertMOB2MSO(mob build.ManageOfferBuilder) *txnbuild.ManageSellOffer {
Price: fmt.Sprintf("%.7f", float64(mob.MO.Price.N)/float64(mob.MO.Price.D)),
}
if mob.O.SourceAccount != nil {
mso.SourceAccount = &txnbuild.SimpleAccount{
AccountID: mob.O.SourceAccount.Address(),
}
mso.SourceAccount = mob.O.SourceAccount.Address()
}

if mob.MO.Buying.Type == xdr.AssetTypeAssetTypeNative {
Expand Down
4 changes: 2 additions & 2 deletions gui/backend/autogenerate_bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (s *APIServer) setupTestnetAccount(address string, signer string, botName s
Line: txnbuild.CreditAsset{
Code: "COUPON",
Issuer: "GBMMZMK2DC4FFP4CAI6KCVNCQ7WLO5A7DQU7EC7WGHRDQBZB763X4OQI",
},
}.MustToChangeTrustAsset(),
}
txOps = append(txOps, &trustOp)

Expand All @@ -168,7 +168,7 @@ func (s *APIServer) setupTestnetAccount(address string, signer string, botName s
Code: "COUPON",
Issuer: "GBMMZMK2DC4FFP4CAI6KCVNCQ7WLO5A7DQU7EC7WGHRDQBZB763X4OQI",
},
SourceAccount: &txnbuild.SimpleAccount{AccountID: "GBMMZMK2DC4FFP4CAI6KCVNCQ7WLO5A7DQU7EC7WGHRDQBZB763X4OQI"},
SourceAccount: "GBMMZMK2DC4FFP4CAI6KCVNCQ7WLO5A7DQU7EC7WGHRDQBZB763X4OQI",
}
txOps = append(txOps, &paymentOp)

Expand Down
4 changes: 2 additions & 2 deletions gui/backend/upsert_bot_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (s *APIServer) checkAddTrustline(account hProtocol.Account, kp keypair.KP,
for _, a := range trustlines {
creditAsset := txnbuild.CreditAsset{Code: a.Code, Issuer: a.Issuer}
trustOp := txnbuild.ChangeTrust{
Line: creditAsset,
Line: creditAsset.MustToChangeTrustAsset(),
}
txOps = append(txOps, &trustOp)
log.Printf("added trust asset operation to transaction for asset: %+v\n", a)
Expand All @@ -427,7 +427,7 @@ func (s *APIServer) checkAddTrustline(account hProtocol.Account, kp keypair.KP,
Destination: address,
Amount: "1000.0",
Asset: creditAsset,
SourceAccount: &txnbuild.SimpleAccount{AccountID: "GBMMZMK2DC4FFP4CAI6KCVNCQ7WLO5A7DQU7EC7WGHRDQBZB763X4OQI"},
SourceAccount: "GBMMZMK2DC4FFP4CAI6KCVNCQ7WLO5A7DQU7EC7WGHRDQBZB763X4OQI",
}
txOps = append(txOps, &paymentOp)
log.Printf("added payment operation to transaction for asset because issuer was the public issuer (%s): %+v\n", "GBMMZMK2DC4FFP4CAI6KCVNCQ7WLO5A7DQU7EC7WGHRDQBZB763X4OQI", a)
Expand Down
4 changes: 2 additions & 2 deletions plugins/sdex.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (sdex *SDEX) DeleteOffer(offer hProtocol.Offer) txnbuild.ManageSellOffer {
txOffer := utils.Offer2TxnBuildSellOffer(offer)
txOffer.Amount = "0"
if sdex.SourceAccount != sdex.TradingAccount {
txOffer.SourceAccount = &txnbuild.SimpleAccount{AccountID: sdex.TradingAccount}
txOffer.SourceAccount = sdex.TradingAccount
}
return txOffer
}
Expand Down Expand Up @@ -349,7 +349,7 @@ func (sdex *SDEX) createModifySellOffer(offer *hProtocol.Offer, selling hProtoco
result.OfferID = offer.ID
}
if sdex.SourceAccount != sdex.TradingAccount {
result.SourceAccount = &txnbuild.SimpleAccount{AccountID: sdex.TradingAccount}
result.SourceAccount = sdex.TradingAccount
}

return &result, nil
Expand Down
2 changes: 1 addition & 1 deletion plugins/submitFilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,6 @@ func convertOffer2MSO(offer hProtocol.Offer) *txnbuild.ManageSellOffer {
Amount: offer.Amount,
Price: offer.Price,
OfferID: offer.ID,
SourceAccount: &txnbuild.SimpleAccount{AccountID: offer.Seller},
SourceAccount: offer.Seller,
}
}
4 changes: 2 additions & 2 deletions stellargohorizonclientv300/build/allow_trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ func (m AllowTrustAsset) MutateAllowTrust(o *xdr.AllowTrustOp) (err error) {
var code xdr.AssetCode4
byteArray := []byte(m.Code)
copy(code[:], byteArray[0:length])
o.Asset, err = xdr.NewAllowTrustOpAsset(xdr.AssetTypeAssetTypeCreditAlphanum4, code)
o.Asset, err = xdr.NewAssetCode(xdr.AssetTypeAssetTypeCreditAlphanum4, code)
case length >= 5 && length <= 12:
var code xdr.AssetCode12
byteArray := []byte(m.Code)
copy(code[:], byteArray[0:length])
o.Asset, err = xdr.NewAllowTrustOpAsset(xdr.AssetTypeAssetTypeCreditAlphanum12, code)
o.Asset, err = xdr.NewAssetCode(xdr.AssetTypeAssetTypeCreditAlphanum12, code)
default:
err = errors.New("Asset code length is invalid")
}
Expand Down
4 changes: 2 additions & 2 deletions stellargohorizonclientv300/build/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func (a Asset) ToXDR() (xdr.Asset, error) {
var codeArray xdr.AssetCode4
byteArray := []byte(a.Code)
copy(codeArray[:], byteArray[0:length])
asset := xdr.AssetAlphaNum4{AssetCode: codeArray, Issuer: issuer}
asset := xdr.AlphaNum4{AssetCode: codeArray, Issuer: issuer}
return xdr.NewAsset(xdr.AssetTypeAssetTypeCreditAlphanum4, asset)
case length >= 5 && length <= 12:
var codeArray xdr.AssetCode12
byteArray := []byte(a.Code)
copy(codeArray[:], byteArray[0:length])
asset := xdr.AssetAlphaNum12{AssetCode: codeArray, Issuer: issuer}
asset := xdr.AlphaNum12{AssetCode: codeArray, Issuer: issuer}
return xdr.NewAsset(xdr.AssetTypeAssetTypeCreditAlphanum12, asset)
default:
return xdr.Asset{}, errors.New("Asset code length is invalid")
Expand Down
7 changes: 6 additions & 1 deletion stellargohorizonclientv300/build/change_trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ func (m Asset) MutateChangeTrust(o *xdr.ChangeTrustOp) (err error) {
return errors.New("Native asset not allowed")
}

o.Line, err = m.ToXDR()
asset, err := m.ToXDR()
if err != nil {
return err
}

o.Line = asset.ToChangeTrustAsset()
return
}

Expand Down
4 changes: 2 additions & 2 deletions stellargohorizonclientv300/build/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ func createAlphaNumAsset(code, issuerAccountId string) (xdr.Asset, error) {
var codeArray xdr.AssetCode4
byteArray := []byte(code)
copy(codeArray[:], byteArray[0:length])
asset := xdr.AssetAlphaNum4{AssetCode: codeArray, Issuer: issuer}
asset := xdr.AlphaNum4{AssetCode: codeArray, Issuer: issuer}
return xdr.NewAsset(xdr.AssetTypeAssetTypeCreditAlphanum4, asset)
case length >= 5 && length <= 12:
var codeArray xdr.AssetCode12
byteArray := []byte(code)
copy(codeArray[:], byteArray[0:length])
asset := xdr.AssetAlphaNum12{AssetCode: codeArray, Issuer: issuer}
asset := xdr.AlphaNum12{AssetCode: codeArray, Issuer: issuer}
return xdr.NewAsset(xdr.AssetTypeAssetTypeCreditAlphanum12, asset)
default:
return xdr.Asset{}, errors.New("Asset code length is invalid")
Expand Down
14 changes: 7 additions & 7 deletions terminator/terminator.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (t *Terminator) run() {
&txnbuild.ManageData{
Name: terminatorKey,
Value: []byte(tsMillisStr),
SourceAccount: &txnbuild.SimpleAccount{AccountID: t.tradingAccount},
SourceAccount: t.tradingAccount,
},
}

Expand Down Expand Up @@ -146,22 +146,22 @@ func (t *Terminator) deleteOffers(sellOffers []hProtocol.Offer, buyOffers []hPro

// delete existing data entries
ops = append(ops, &txnbuild.ManageData{Name: botKey.FullKey(0),
SourceAccount: &txnbuild.SimpleAccount{AccountID: t.tradingAccount},
SourceAccount: t.tradingAccount,
})
ops = append(ops, &txnbuild.ManageData{Name: botKey.FullKey(1),
SourceAccount: &txnbuild.SimpleAccount{AccountID: t.tradingAccount},
SourceAccount: t.tradingAccount,
})
if len(botKey.AssetBaseIssuer) > 0 {
ops = append(ops, &txnbuild.ManageData{Name: botKey.FullKey(2),
SourceAccount: &txnbuild.SimpleAccount{AccountID: t.tradingAccount},
SourceAccount: t.tradingAccount,
})
}
ops = append(ops, &txnbuild.ManageData{Name: botKey.FullKey(3),
SourceAccount: &txnbuild.SimpleAccount{AccountID: t.tradingAccount},
SourceAccount: t.tradingAccount,
})
if len(botKey.AssetQuoteIssuer) > 0 {
ops = append(ops, &txnbuild.ManageData{Name: botKey.FullKey(4),
SourceAccount: &txnbuild.SimpleAccount{AccountID: t.tradingAccount},
SourceAccount: t.tradingAccount,
})
}

Expand All @@ -170,7 +170,7 @@ func (t *Terminator) deleteOffers(sellOffers []hProtocol.Offer, buyOffers []hPro
ops = append(ops, &txnbuild.ManageData{
Name: terminatorKey,
Value: []byte(tsMillisStr),
SourceAccount: &txnbuild.SimpleAccount{AccountID: t.tradingAccount},
SourceAccount: t.tradingAccount,
})

log.Printf("deleting %d offers and 5 data entries, updating delete timestamp to %s\n", numOffers, tsMillisStr)
Expand Down