Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chowbao committed Jan 8, 2025
1 parent f2fa706 commit 66ac412
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
3 changes: 1 addition & 2 deletions ingest/processors/effects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3489,7 +3489,6 @@ func TestInvokeHostFunctionEffects(t *testing.T) {

admin := randAddr()
asset := xdr.MustNewCreditAsset("TESTER", admin)
nativeAsset := xdr.MustNewNativeAsset()
from, to := randAddr(), randAddr()
fromContractBytes, toContractBytes := xdr.Hash{}, xdr.Hash{1}
fromContract := strkey.MustEncode(strkey.VersionByteContract, fromContractBytes[:])
Expand Down Expand Up @@ -3691,7 +3690,7 @@ func TestInvokeHostFunctionEffects(t *testing.T) {
},
}, {
desc: "transfer native",
asset: nativeAsset,
asset: xdr.MustNewNativeAsset(),
eventType: contractevents.EventTypeTransfer,
expected: []EffectOutput{
{
Expand Down
4 changes: 3 additions & 1 deletion ingest/processors/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ func TransformLedger(inputLedger historyarchive.Ledger, lcm xdr.LedgerCloseMeta)

var outputSorobanFeeWrite1Kb int64
var outputTotalByteSizeOfBucketList uint64

lcmV1, ok := lcm.GetV1()
if ok {
extV1, ok := lcmV1.Ext.GetV1()
var extV1 xdr.LedgerCloseMetaExtV1
extV1, ok = lcmV1.Ext.GetV1()
if ok {
outputSorobanFeeWrite1Kb = int64(extV1.SorobanFeeWrite1Kb)
}
Expand Down
9 changes: 5 additions & 4 deletions ingest/processors/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func TransformOperation(operation xdr.Operation, operationIndex int32, transacti

var outputSourceAccountMuxed null.String
if sourceAccount.Type == xdr.CryptoKeyTypeKeyTypeMuxedEd25519 {
muxedAddress, err := sourceAccount.GetAddress()
var muxedAddress string
muxedAddress, err = sourceAccount.GetAddress()
if err != nil {
return OperationOutput{}, err
}
Expand Down Expand Up @@ -961,7 +962,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT
details["reserve_a_deposit_amount"] = depositA

//Process ReserveB Details
if err := addAssetDetailsToOperationDetails(details, assetB, "reserve_b"); err != nil {
if err = addAssetDetailsToOperationDetails(details, assetB, "reserve_b"); err != nil {
return details, err
}
details["reserve_b_max_amount"] = ConvertStroopValueToReal(op.MaxAmountB)
Expand All @@ -971,10 +972,10 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT
}
details["reserve_b_deposit_amount"] = depositB

if err := addPriceDetails(details, op.MinPrice, "min"); err != nil {
if err = addPriceDetails(details, op.MinPrice, "min"); err != nil {
return details, err
}
if err := addPriceDetails(details, op.MaxPrice, "max"); err != nil {
if err = addPriceDetails(details, op.MaxPrice, "max"); err != nil {
return details, err
}

Expand Down
20 changes: 14 additions & 6 deletions ingest/processors/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,13 @@ func extractClaimedOffers(operationResults []xdr.OperationResult, operationIndex
switch operationType {
case xdr.OperationTypeManageBuyOffer:
var buyOfferResult xdr.ManageBuyOfferResult
var success xdr.ManageOfferSuccessResult

if buyOfferResult, ok = operationTr.GetManageBuyOfferResult(); !ok {
err = fmt.Errorf("could not get ManageBuyOfferResult for operation at index %d", operationIndex)
return
}
if success, ok := buyOfferResult.GetSuccess(); ok {
if success, ok = buyOfferResult.GetSuccess(); ok {
claimedOffers = success.OffersClaimed
BuyingOffer = success.Offer.Offer
return
Expand All @@ -186,12 +188,13 @@ func extractClaimedOffers(operationResults []xdr.OperationResult, operationIndex

case xdr.OperationTypeManageSellOffer:
var sellOfferResult xdr.ManageSellOfferResult
var success xdr.ManageOfferSuccessResult
if sellOfferResult, ok = operationTr.GetManageSellOfferResult(); !ok {
err = fmt.Errorf("could not get ManageSellOfferResult for operation at index %d", operationIndex)
return
}

if success, ok := sellOfferResult.GetSuccess(); ok {
if success, ok = sellOfferResult.GetSuccess(); ok {
claimedOffers = success.OffersClaimed
BuyingOffer = success.Offer.Offer
return
Expand All @@ -216,13 +219,15 @@ func extractClaimedOffers(operationResults []xdr.OperationResult, operationIndex

case xdr.OperationTypePathPaymentStrictSend:
var pathSendResult xdr.PathPaymentStrictSendResult
var success xdr.PathPaymentStrictSendResultSuccess

sellerIsExact = null.BoolFrom(false)
if pathSendResult, ok = operationTr.GetPathPaymentStrictSendResult(); !ok {
err = fmt.Errorf("could not get PathPaymentStrictSendResult for operation at index %d", operationIndex)
return
}

success, ok := pathSendResult.GetSuccess()
success, ok = pathSendResult.GetSuccess()
if ok {
claimedOffers = success.Offers
return
Expand Down Expand Up @@ -262,7 +267,8 @@ func findTradeSellPrice(t ingest.LedgerTransaction, operationIndex int32, trade
if err := key.SetOffer(trade.SellerId(), uint64(trade.OfferId())); err != nil {

Check failure on line 267 in ingest/processors/trade.go

View workflow job for this annotation

GitHub Actions / check (ubuntu-22.04, 1.23)

declaration of "err" shadows declaration at line 261
return 0, 0, errors.Wrap(err, "Could not create offer ledger key")
}
change, err := findLatestOperationChange(t, operationIndex, key)
var change ingest.Change
change, err = findLatestOperationChange(t, operationIndex, key)
if err != nil {
return 0, 0, errors.Wrap(err, "could not find change for trade offer")
}
Expand All @@ -281,7 +287,8 @@ func findLatestOperationChange(t ingest.LedgerTransaction, operationIndex int32,
for i := len(changes) - 1; i >= 0; i-- {
change = changes[i]
if change.Pre != nil {
preKey, err := change.Pre.LedgerKey()
var preKey xdr.LedgerKey
preKey, err = change.Pre.LedgerKey()
if err != nil {
return ingest.Change{}, errors.Wrap(err, "could not determine ledger key for change")

Expand All @@ -300,7 +307,8 @@ func findPoolFee(t ingest.LedgerTransaction, operationIndex int32, poolID xdr.Po
if err := key.SetLiquidityPool(poolID); err != nil {

Check failure on line 307 in ingest/processors/trade.go

View workflow job for this annotation

GitHub Actions / check (ubuntu-22.04, 1.23)

declaration of "err" shadows declaration at line 305
return 0, errors.Wrap(err, "Could not create liquidity pool ledger key")
}
change, err := findLatestOperationChange(t, operationIndex, key)
var change ingest.Change
change, err = findLatestOperationChange(t, operationIndex, key)
if err != nil {
return 0, errors.Wrap(err, "could not find change for liquidity pool")
}
Expand Down

0 comments on commit 66ac412

Please sign in to comment.