diff --git a/bitcoin/client.go b/bitcoin/client.go index bdb1efd..a3b768f 100644 --- a/bitcoin/client.go +++ b/bitcoin/client.go @@ -516,9 +516,9 @@ func (b *Client) parseTransactions( "block hash", block.Hash, "transaction hash", transaction.Hash, ) - + status := SuccessStatus for _, op := range txOps { - op.Status = SkippedStatus + op.Status = &status } } @@ -675,13 +675,14 @@ func (b *Client) parseOutputTransactionOperation( coinChange = nil } + status := SuccessStatus return &types.Operation{ OperationIdentifier: &types.OperationIdentifier{ Index: index, NetworkIndex: &networkIndex, }, Type: OutputOpType, - Status: SuccessStatus, + Status: &status, Account: account, Amount: &types.Amount{ Value: strconv.FormatInt(int64(amount), 10), @@ -732,13 +733,14 @@ func (b *Client) parseInputTransactionOperation( return nil, fmt.Errorf("%w: unable to negate previous output", err) } + status := SuccessStatus return &types.Operation{ OperationIdentifier: &types.OperationIdentifier{ Index: index, NetworkIndex: &networkIndex, }, Type: InputOpType, - Status: SuccessStatus, + Status: &status, Account: accountCoin.Account, Amount: &types.Amount{ Value: newValue, @@ -794,13 +796,14 @@ func (b *Client) coinbaseTxOperation( return nil, fmt.Errorf("%w: unable to get input metadata", err) } + status := SuccessStatus return &types.Operation{ OperationIdentifier: &types.OperationIdentifier{ Index: index, NetworkIndex: &networkIndex, }, Type: CoinbaseOpType, - Status: SuccessStatus, + Status: &status, Metadata: metadata, }, nil } diff --git a/bitcoin/client_test.go b/bitcoin/client_test.go index 4e1ab94..c0fc785 100644 --- a/bitcoin/client_test.go +++ b/bitcoin/client_test.go @@ -706,6 +706,7 @@ func mustMarshalMap(v interface{}) map[string]interface{} { } func TestParseBlock(t *testing.T) { + status := SuccessStatus tests := map[string]struct { block *Block coins map[string]*storage.AccountCoin @@ -735,7 +736,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(0), }, Type: CoinbaseOpType, - Status: SuccessStatus, + Status: &status, Metadata: mustMarshalMap(&OperationMetadata{ Coinbase: "04ffff001d02fd04", Sequence: 4294967295, @@ -747,7 +748,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(0), }, Type: OutputOpType, - Status: SuccessStatus, + Status: &status, Account: &types.AccountIdentifier{ Address: "4104f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446aac", // nolint }, @@ -788,7 +789,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(0), }, Type: OutputOpType, - Status: SuccessStatus, + Status: &status, Account: &types.AccountIdentifier{ Address: "mmtKKnjqTPdkBnBMbNt5Yu2SCwpMaEshEL", // nolint }, @@ -820,7 +821,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(1), }, Type: OutputOpType, - Status: SuccessStatus, + Status: &status, Account: &types.AccountIdentifier{ Address: "4852fe372ff7534c16713b3146bbc1e86379c70bea4d5c02fb1fa0112980a081:1", }, @@ -928,7 +929,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(0), }, Type: CoinbaseOpType, - Status: SuccessStatus, + Status: &status, Metadata: mustMarshalMap(&OperationMetadata{ Coinbase: "044c86041b020602", Sequence: 4294967295, @@ -940,7 +941,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(0), }, Type: OutputOpType, - Status: SuccessStatus, + Status: &status, Account: &types.AccountIdentifier{ Address: "34qkc2iac6RsyxZVfyE2S5U5WcRsbg2dpK", }, @@ -972,7 +973,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(1), }, Type: OutputOpType, - Status: SuccessStatus, + Status: &status, Account: &types.AccountIdentifier{ Address: "6a24aa21a9ed10109f4b82aa3ed7ec9d02a2a90246478b3308c8b85daf62fe501d58d05727a4", }, @@ -1007,7 +1008,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(0), }, Type: InputOpType, - Status: SuccessStatus, + Status: &status, Amount: &types.Amount{ Value: "-5000000000", Currency: MainnetCurrency, @@ -1035,7 +1036,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(0), }, Type: OutputOpType, - Status: SuccessStatus, + Status: &status, Account: &types.AccountIdentifier{ Address: "1JqDybm2nWTENrHvMyafbSXXtTk5Uv5QAn", }, @@ -1067,7 +1068,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(1), }, Type: OutputOpType, - Status: SuccessStatus, + Status: &status, Account: &types.AccountIdentifier{ Address: "1EYTGtG4LnFfiMvjJdsU7GMGCQvsRSjYhx", }, @@ -1112,7 +1113,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(0), }, Type: InputOpType, - Status: SuccessStatus, + Status: &status, Amount: &types.Amount{ Value: "-3467607", Currency: MainnetCurrency, @@ -1144,7 +1145,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(1), }, Type: InputOpType, - Status: SuccessStatus, + Status: &status, Amount: &types.Amount{ Value: "0", Currency: MainnetCurrency, @@ -1172,7 +1173,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(2), }, Type: InputOpType, - Status: SuccessStatus, + Status: &status, Amount: &types.Amount{ Value: "-556000000", Currency: MainnetCurrency, @@ -1200,7 +1201,7 @@ func TestParseBlock(t *testing.T) { NetworkIndex: int64Pointer(0), }, Type: OutputOpType, - Status: SuccessStatus, + Status: &status, Account: &types.AccountIdentifier{ Address: "76a914c398efa9c392ba6013c5e04ee729755ef7f58b3288ac", }, diff --git a/go.sum b/go.sum index 6c34be9..ab30588 100644 --- a/go.sum +++ b/go.sum @@ -62,8 +62,6 @@ github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9/go.mod h1:1MxXX1Ux4x6mqPmjkUgTP1CdXIBXKX7T+Jk9Gxrmx+U= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/coinbase/rosetta-sdk-go v0.5.9 h1:CuGQE3HFmYwdEACJnuOtVI9cofqPsGvq6FdFIzaOPKI= -github.com/coinbase/rosetta-sdk-go v0.5.9/go.mod h1:xd4wYUhV3LkY78SPH8BUhc88rXfn2jYgN9BfiSjbcvM= github.com/coinbase/rosetta-sdk-go v0.6.0 h1:U8/NhkPo7CGJR8Ud82Y0HqtujXSVzGZKscmxOHsmS54= github.com/coinbase/rosetta-sdk-go v0.6.0/go.mod h1:pqBibzTcpz0mLqb7is8fo2qf93tcHjItJ3u7Yud8RI4= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= @@ -102,8 +100,6 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/ethereum/go-ethereum v1.9.23 h1:SIKhg/z4Q7AbvqcxuPYvMxf36che/Rq/Pp0IdYEkbtw= github.com/ethereum/go-ethereum v1.9.23/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6wCncIu1hNwHpM= github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= -github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= @@ -189,18 +185,11 @@ github.com/lucasjones/reggen v0.0.0-20180717132126-cdb49ff09d77 h1:6xiz3+ZczT3M4 github.com/lucasjones/reggen v0.0.0-20180717132126-cdb49ff09d77/go.mod h1:5ELEyG+X8f+meRWHuqUOewBOhvHkl7M76pdGEansxW4= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw= -github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM= -github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= @@ -363,7 +352,6 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -371,7 +359,6 @@ golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/indexer/indexer.go b/indexer/indexer.go index 47a3649..1f50002 100644 --- a/indexer/indexer.go +++ b/indexer/indexer.go @@ -255,7 +255,7 @@ func (i *Indexer) Sync(ctx context.Context) error { // If previously processed blocks exist in storage, they are fetched. // Otherwise, none are provided to the cache (the syncer will not attempt // a reorg if the cache is empty). - pastBlocks := i.blockStorage.CreateBlockCache(ctx) + pastBlocks := i.blockStorage.CreateBlockCache(ctx, int(head.Index)) syncer := syncer.New( i.network, diff --git a/indexer/indexer_test.go b/indexer/indexer_test.go index 314a2f5..5ea8b4a 100644 --- a/indexer/indexer_test.go +++ b/indexer/indexer_test.go @@ -267,6 +267,7 @@ func TestIndexer_Transactions(t *testing.T) { } transactions := []*types.Transaction{} + status := bitcoin.SuccessStatus for j := 0; j < 5; j++ { rawHash := fmt.Sprintf("block %d transaction %d", i, j) hash := fmt.Sprintf("%x", sha256.Sum256([]byte(rawHash))) @@ -286,7 +287,7 @@ func TestIndexer_Transactions(t *testing.T) { Index: 0, NetworkIndex: &index0, }, - Status: bitcoin.SuccessStatus, + Status: &status, Type: bitcoin.OutputOpType, Account: &types.AccountIdentifier{ Address: rawHash, @@ -486,6 +487,7 @@ func TestIndexer_Reorg(t *testing.T) { } transactions := []*types.Transaction{} + status := bitcoin.SuccessStatus for j := 0; j < 5; j++ { rawHash := fmt.Sprintf("block %d transaction %d", i, j) hash := fmt.Sprintf("%x", sha256.Sum256([]byte(rawHash))) @@ -505,7 +507,7 @@ func TestIndexer_Reorg(t *testing.T) { Index: 0, NetworkIndex: &index0, }, - Status: bitcoin.SuccessStatus, + Status: &status, Type: bitcoin.OutputOpType, Account: &types.AccountIdentifier{ Address: rawHash, diff --git a/main.go b/main.go index 4b5d1c6..e8f110e 100644 --- a/main.go +++ b/main.go @@ -157,6 +157,7 @@ func main() { services.HistoricalBalanceLookup, []*types.NetworkIdentifier{cfg.Network}, nil, + false, ) if err != nil { logger.Fatalw("unable to create new server asserter", "error", err) diff --git a/services/account_service_test.go b/services/account_service_test.go index ce94fb1..323e6c5 100644 --- a/services/account_service_test.go +++ b/services/account_service_test.go @@ -93,7 +93,6 @@ func TestAccountBalance_Online_Current(t *testing.T) { assert.Equal(t, &types.AccountBalanceResponse{ BlockIdentifier: block, - Coins: coins, Balances: []*types.Amount{ { Value: "25",