Skip to content

Commit

Permalink
Showing 8 changed files with 474 additions and 437 deletions.
Original file line number Diff line number Diff line change
@@ -4,14 +4,15 @@ import (
"context"

"github.com/guregu/null"

"github.com/stellar/go/support/db"
)

// EffectBatchInsertBuilder is used to insert effects into the
// history_effects table
type EffectBatchInsertBuilder interface {
Add(
accountID int64,
accountID FutureAccountID,
muxedAccount null.String,
operationID int64,
order uint32,
@@ -37,7 +38,7 @@ func (q *Q) NewEffectBatchInsertBuilder() EffectBatchInsertBuilder {

// Add adds a effect to the batch
func (i *effectBatchInsertBuilder) Add(
accountID int64,
accountID FutureAccountID,
muxedAccount null.String,
operationID int64,
order uint32,
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import (
"testing"

"github.com/guregu/null"

"github.com/stellar/go/services/horizon/internal/test"
"github.com/stellar/go/toid"
)
@@ -18,8 +19,7 @@ func TestAddEffect(t *testing.T) {

address := "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY"
muxedAddres := "MAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSAAAAAAAAAAE2LP26"
accounIDs, err := q.CreateAccounts(tt.Ctx, []string{address}, 1)
tt.Assert.NoError(err)
accountLoader := NewAccountLoader()

builder := q.NewEffectBatchInsertBuilder()
sequence := int32(56)
@@ -29,7 +29,7 @@ func TestAddEffect(t *testing.T) {
})

err = builder.Add(
accounIDs[address],
accountLoader.GetFuture(address),
null.StringFrom(muxedAddres),
toid.New(sequence, 1, 1).ToInt64(),
1,
@@ -38,6 +38,7 @@ func TestAddEffect(t *testing.T) {
)
tt.Assert.NoError(err)

tt.Assert.NoError(accountLoader.Exec(tt.Ctx, q))
tt.Assert.NoError(builder.Exec(tt.Ctx, q))
tt.Assert.NoError(q.Commit())

35 changes: 15 additions & 20 deletions services/horizon/internal/db2/history/effect_test.go
Original file line number Diff line number Diff line change
@@ -23,28 +23,27 @@ func TestEffectsForLiquidityPool(t *testing.T) {
// Insert Effect
address := "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY"
muxedAddres := "MAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSAAAAAAAAAAE2LP26"
accountIDs, err := q.CreateAccounts(tt.Ctx, []string{address}, 1)
tt.Assert.NoError(err)
accountLoader := NewAccountLoader()

builder := q.NewEffectBatchInsertBuilder()
sequence := int32(56)
details, err := json.Marshal(map[string]string{
"amount": "1000.0000000",
"asset_type": "native",
})
tt.Assert.NoError(err)
opID := toid.New(sequence, 1, 1).ToInt64()
err = builder.Add(
accountIDs[address],
tt.Assert.NoError(builder.Add(
accountLoader.GetFuture(address),
null.StringFrom(muxedAddres),
opID,
1,
3,
details,
)
tt.Assert.NoError(err)
))

err = builder.Exec(tt.Ctx, q)
tt.Assert.NoError(err)
tt.Assert.NoError(accountLoader.Exec(tt.Ctx, q))
tt.Assert.NoError(builder.Exec(tt.Ctx, q))

// Insert Liquidity Pool history
liquidityPoolID := "abcde"
@@ -79,8 +78,7 @@ func TestEffectsForTrustlinesSponsorshipEmptyAssetType(t *testing.T) {

address := "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY"
muxedAddres := "MAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSAAAAAAAAAAE2LP26"
accountIDs, err := q.CreateAccounts(tt.Ctx, []string{address}, 1)
tt.Assert.NoError(err)
accountLoader := NewAccountLoader()

builder := q.NewEffectBatchInsertBuilder()
sequence := int32(56)
@@ -142,27 +140,24 @@ func TestEffectsForTrustlinesSponsorshipEmptyAssetType(t *testing.T) {

for i, test := range tests {
var bytes []byte
bytes, err = json.Marshal(test.details)
bytes, err := json.Marshal(test.details)
tt.Require.NoError(err)

err = builder.Add(
accountIDs[address],
tt.Require.NoError(builder.Add(
accountLoader.GetFuture(address),
null.StringFrom(muxedAddres),
opID,
uint32(i),
test.effectType,
bytes,
)
tt.Require.NoError(err)
))
}

err = builder.Exec(tt.Ctx, q)
tt.Require.NoError(err)
tt.Require.NoError(accountLoader.Exec(tt.Ctx, q))
tt.Require.NoError(builder.Exec(tt.Ctx, q))
tt.Assert.NoError(q.Commit())

var results []Effect
err = q.Effects().Select(tt.Ctx, &results)
tt.Require.NoError(err)
tt.Require.NoError(q.Effects().Select(tt.Ctx, &results))
tt.Require.Len(results, len(tests))

for i, test := range tests {
9 changes: 5 additions & 4 deletions services/horizon/internal/db2/history/fee_bump_scenario.go
Original file line number Diff line number Diff line change
@@ -10,12 +10,13 @@ import (
sq "github.com/Masterminds/squirrel"
"github.com/guregu/null"

"github.com/stretchr/testify/assert"

"github.com/stellar/go/ingest"
"github.com/stellar/go/network"
"github.com/stellar/go/services/horizon/internal/test"
"github.com/stellar/go/toid"
"github.com/stellar/go/xdr"
"github.com/stretchr/testify/assert"
)

func ledgerToMap(ledger Ledger) map[string]interface{} {
@@ -285,18 +286,18 @@ func FeeBumpScenario(tt *test.T, q *Q, successful bool) FeeBumpFixture {
details, err = json.Marshal(map[string]interface{}{"new_seq": 98})
tt.Assert.NoError(err)

accounIDs, err := q.CreateAccounts(ctx, []string{account.Address()}, 1)
tt.Assert.NoError(err)
accountLoader := NewAccountLoader()

err = effectBuilder.Add(
accounIDs[account.Address()],
accountLoader.GetFuture(account.Address()),
null.String{},
toid.New(fixture.Ledger.Sequence, 1, 1).ToInt64(),
1,
EffectSequenceBumped,
details,
)
tt.Assert.NoError(err)
tt.Assert.NoError(accountLoader.Exec(ctx, q))
tt.Assert.NoError(effectBuilder.Exec(ctx, q))

tt.Assert.NoError(q.Commit())
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ type MockEffectBatchInsertBuilder struct {

// Add mock
func (m *MockEffectBatchInsertBuilder) Add(
accountID int64,
accountID FutureAccountID,
muxedAccount null.String,
operationID int64,
order uint32,
570 changes: 305 additions & 265 deletions services/horizon/internal/ingest/processors/effects_processor.go

Large diffs are not rendered by default.

215 changes: 90 additions & 125 deletions services/horizon/internal/ingest/processors/effects_processor_test.go

Large diffs are not rendered by default.

68 changes: 51 additions & 17 deletions services/horizon/internal/ingest/processors/operations_processor.go
Original file line number Diff line number Diff line change
@@ -294,7 +294,9 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
addAccountAndMuxedAccountDetails(details, *source, "from")
addAccountAndMuxedAccountDetails(details, op.Destination, "to")
details["amount"] = amount.String(op.Amount)
addAssetDetails(details, op.Asset, "")
if err := addAssetDetails(details, op.Asset, ""); err != nil {
return nil, err
}
case xdr.OperationTypePathPaymentStrictReceive:
op := operation.operation.Body.MustPathPaymentStrictReceiveOp()
addAccountAndMuxedAccountDetails(details, *source, "from")
@@ -303,8 +305,12 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
details["amount"] = amount.String(op.DestAmount)
details["source_amount"] = amount.String(0)
details["source_max"] = amount.String(op.SendMax)
addAssetDetails(details, op.DestAsset, "")
addAssetDetails(details, op.SendAsset, "source_")
if err := addAssetDetails(details, op.DestAsset, ""); err != nil {
return nil, err
}
if err := addAssetDetails(details, op.SendAsset, "source_"); err != nil {
return nil, err
}

if operation.transaction.Result.Successful() {
result := operation.OperationResult().MustPathPaymentStrictReceiveResult()
@@ -314,7 +320,9 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
var path = make([]map[string]interface{}, len(op.Path))
for i := range op.Path {
path[i] = make(map[string]interface{})
addAssetDetails(path[i], op.Path[i], "")
if err := addAssetDetails(path[i], op.Path[i], ""); err != nil {
return nil, err
}
}
details["path"] = path

@@ -326,8 +334,12 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
details["amount"] = amount.String(0)
details["source_amount"] = amount.String(op.SendAmount)
details["destination_min"] = amount.String(op.DestMin)
addAssetDetails(details, op.DestAsset, "")
addAssetDetails(details, op.SendAsset, "source_")
if err := addAssetDetails(details, op.DestAsset, ""); err != nil {
return nil, err
}
if err := addAssetDetails(details, op.SendAsset, "source_"); err != nil {
return nil, err
}

if operation.transaction.Result.Successful() {
result := operation.OperationResult().MustPathPaymentStrictSendResult()
@@ -337,7 +349,9 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
var path = make([]map[string]interface{}, len(op.Path))
for i := range op.Path {
path[i] = make(map[string]interface{})
addAssetDetails(path[i], op.Path[i], "")
if err := addAssetDetails(path[i], op.Path[i], ""); err != nil {
return nil, err
}
}
details["path"] = path
case xdr.OperationTypeManageBuyOffer:
@@ -349,8 +363,12 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
"n": op.Price.N,
"d": op.Price.D,
}
addAssetDetails(details, op.Buying, "buying_")
addAssetDetails(details, op.Selling, "selling_")
if err := addAssetDetails(details, op.Buying, "buying_"); err != nil {
return nil, err
}
if err := addAssetDetails(details, op.Selling, "selling_"); err != nil {
return nil, err
}
case xdr.OperationTypeManageSellOffer:
op := operation.operation.Body.MustManageSellOfferOp()
details["offer_id"] = op.OfferId
@@ -360,8 +378,12 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
"n": op.Price.N,
"d": op.Price.D,
}
addAssetDetails(details, op.Buying, "buying_")
addAssetDetails(details, op.Selling, "selling_")
if err := addAssetDetails(details, op.Buying, "buying_"); err != nil {
return nil, err
}
if err := addAssetDetails(details, op.Selling, "selling_"); err != nil {
return nil, err
}
case xdr.OperationTypeCreatePassiveSellOffer:
op := operation.operation.Body.MustCreatePassiveSellOfferOp()
details["amount"] = amount.String(op.Amount)
@@ -370,8 +392,12 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
"n": op.Price.N,
"d": op.Price.D,
}
addAssetDetails(details, op.Buying, "buying_")
addAssetDetails(details, op.Selling, "selling_")
if err := addAssetDetails(details, op.Buying, "buying_"); err != nil {
return nil, err
}
if err := addAssetDetails(details, op.Selling, "selling_"); err != nil {
return nil, err
}
case xdr.OperationTypeSetOptions:
op := operation.operation.Body.MustSetOptionsOp()

@@ -418,14 +444,18 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
return nil, err
}
} else {
addAssetDetails(details, op.Line.ToAsset(), "")
if err := addAssetDetails(details, op.Line.ToAsset(), ""); err != nil {
return nil, err
}
details["trustee"] = details["asset_issuer"]
}
addAccountAndMuxedAccountDetails(details, *source, "trustor")
details["limit"] = amount.String(op.Limit)
case xdr.OperationTypeAllowTrust:
op := operation.operation.Body.MustAllowTrustOp()
addAssetDetails(details, op.Asset.ToAsset(source.ToAccountId()), "")
if err := addAssetDetails(details, op.Asset.ToAsset(source.ToAccountId()), ""); err != nil {
return nil, err
}
addAccountAndMuxedAccountDetails(details, *source, "trustee")
details["trustor"] = op.Trustor.Address()
details["authorize"] = xdr.TrustLineFlags(op.Authorize).IsAuthorized()
@@ -496,7 +526,9 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
}
case xdr.OperationTypeClawback:
op := operation.operation.Body.MustClawbackOp()
addAssetDetails(details, op.Asset, "")
if err := addAssetDetails(details, op.Asset, ""); err != nil {
return nil, err
}
addAccountAndMuxedAccountDetails(details, op.From, "from")
details["amount"] = amount.String(op.Amount)
case xdr.OperationTypeClawbackClaimableBalance:
@@ -509,7 +541,9 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
case xdr.OperationTypeSetTrustLineFlags:
op := operation.operation.Body.MustSetTrustLineFlagsOp()
details["trustor"] = op.Trustor.Address()
addAssetDetails(details, op.Asset, "")
if err := addAssetDetails(details, op.Asset, ""); err != nil {
return nil, err
}
if op.SetFlags > 0 {
addTrustLineFlagDetails(details, xdr.TrustLineFlags(op.SetFlags), "set")
}

0 comments on commit 8775648

Please sign in to comment.