From 43d5769325cab36791a0e4f87fffe838bf783660 Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Mon, 5 Oct 2020 18:25:02 +0200 Subject: [PATCH] services/horizon: Insert signers's sponsorship information during state ingestion --- .../processors/signer_processor_test.go | 48 +++++++++++++++++++ .../expingest/processors/signers_processor.go | 8 ++++ 2 files changed, 56 insertions(+) diff --git a/services/horizon/internal/expingest/processors/signer_processor_test.go b/services/horizon/internal/expingest/processors/signer_processor_test.go index 4c720bed6b..1688182425 100644 --- a/services/horizon/internal/expingest/processors/signer_processor_test.go +++ b/services/horizon/internal/expingest/processors/signer_processor_test.go @@ -4,6 +4,7 @@ package processors import ( "testing" + "github.com/guregu/null" ingesterrors "github.com/stellar/go/exp/ingest/errors" "github.com/stellar/go/exp/ingest/io" "github.com/stellar/go/services/horizon/internal/db2/history" @@ -98,6 +99,53 @@ func (s *AccountsSignerProcessorTestSuiteState) TestCreatesSigners() { } +func (s *AccountsSignerProcessorTestSuiteState) TestCreatesSignerWithSponsor() { + s.mockBatchInsertBuilder. + On("Add", history.AccountSigner{ + Account: "GCCCU34WDY2RATQTOOQKY6SZWU6J5DONY42SWGW2CIXGW4LICAGNRZKX", + Signer: "GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML", + Weight: int32(10), + Sponsor: null.StringFrom("GDWZ6MKJP5ESVIB7O5RW4UFFGSCDILPEKDXWGG4HXXSHEZZPTKLR6UVG"), + }).Return(nil).Once() + + sponsorshipDescriptor := xdr.MustAddress("GDWZ6MKJP5ESVIB7O5RW4UFFGSCDILPEKDXWGG4HXXSHEZZPTKLR6UVG") + + err := s.processor.ProcessChange(io.Change{ + Type: xdr.LedgerEntryTypeAccount, + Pre: nil, + Post: &xdr.LedgerEntry{ + Data: xdr.LedgerEntryData{ + Type: xdr.LedgerEntryTypeAccount, + Account: &xdr.AccountEntry{ + AccountId: xdr.MustAddress("GCCCU34WDY2RATQTOOQKY6SZWU6J5DONY42SWGW2CIXGW4LICAGNRZKX"), + Signers: []xdr.Signer{ + { + Key: xdr.MustSigner("GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML"), + Weight: 10, + }, + }, + Ext: xdr.AccountEntryExt{ + V: 1, + V1: &xdr.AccountEntryExtensionV1{ + Ext: xdr.AccountEntryExtensionV1Ext{ + V: 2, + V2: &xdr.AccountEntryExtensionV2{ + NumSponsored: 1, + NumSponsoring: 0, + SignerSponsoringIDs: []xdr.SponsorshipDescriptor{ + &sponsorshipDescriptor, + }, + }, + }, + }, + }, + }, + }, + }, + }) + s.Assert().NoError(err) +} + func TestAccountsSignerProcessorTestSuiteLedger(t *testing.T) { suite.Run(t, new(AccountsSignerProcessorTestSuiteLedger)) } diff --git a/services/horizon/internal/expingest/processors/signers_processor.go b/services/horizon/internal/expingest/processors/signers_processor.go index 91d2c383bb..626f8754c1 100644 --- a/services/horizon/internal/expingest/processors/signers_processor.go +++ b/services/horizon/internal/expingest/processors/signers_processor.go @@ -1,6 +1,7 @@ package processors import ( + "github.com/guregu/null" ingesterrors "github.com/stellar/go/exp/ingest/errors" "github.com/stellar/go/exp/ingest/io" "github.com/stellar/go/services/horizon/internal/db2/history" @@ -61,11 +62,18 @@ func (p *SignersProcessor) ProcessChange(change io.Change) error { accountEntry := change.Post.Data.MustAccount() account := accountEntry.AccountId.Address() + sponsors := accountEntry.SponsorPerSigner() for signer, weight := range accountEntry.SignerSummary() { + var sponsor null.String + if sponsorDesc, isSponsored := sponsors[signer]; isSponsored { + sponsor = null.StringFrom(sponsorDesc.Address()) + } + err := p.batch.Add(history.AccountSigner{ Account: account, Signer: signer, Weight: weight, + Sponsor: sponsor, }) if err != nil { return errors.Wrap(err, "Error adding row to accountSignerBatch")