Skip to content

Commit 07362e9

Browse files
Merge pull request #43 from coinbase/pr/39
[Security] Update `go`
2 parents 5e1ea91 + 0b061b9 commit 07362e9

File tree

14 files changed

+148
-109
lines changed

14 files changed

+148
-109
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ version: 2.1
1616
executors:
1717
default:
1818
docker:
19-
- image: circleci/golang:1.13
19+
- image: circleci/golang:1.15
2020
user: root # go directory is owned by root
2121
working_directory: /go/src/github.com/coinbase/rosetta-bitcoin
2222
environment:

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ RUN mkdir -p /app \
4444
WORKDIR /app
4545

4646
RUN apt-get update && apt-get install -y curl make gcc g++
47-
ENV GOLANG_VERSION 1.15.2
48-
ENV GOLANG_DOWNLOAD_SHA256 b49fda1ca29a1946d6bb2a5a6982cf07ccd2aba849289508ee0f9918f6bb4552
47+
ENV GOLANG_VERSION 1.15.5
48+
ENV GOLANG_DOWNLOAD_SHA256 9a58494e8da722c3aef248c9227b0e9c528c7318309827780f16220998180a0d
4949
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
5050

5151
RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \

bitcoin/client.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,8 @@ func (b *Client) parseTransactions(
516516
"block hash", block.Hash,
517517
"transaction hash", transaction.Hash,
518518
)
519-
520519
for _, op := range txOps {
521-
op.Status = SkippedStatus
520+
op.Status = types.String(SkippedStatus)
522521
}
523522
}
524523

@@ -681,7 +680,7 @@ func (b *Client) parseOutputTransactionOperation(
681680
NetworkIndex: &networkIndex,
682681
},
683682
Type: OutputOpType,
684-
Status: SuccessStatus,
683+
Status: types.String(SuccessStatus),
685684
Account: account,
686685
Amount: &types.Amount{
687686
Value: strconv.FormatInt(int64(amount), 10),
@@ -738,7 +737,7 @@ func (b *Client) parseInputTransactionOperation(
738737
NetworkIndex: &networkIndex,
739738
},
740739
Type: InputOpType,
741-
Status: SuccessStatus,
740+
Status: types.String(SuccessStatus),
742741
Account: accountCoin.Account,
743742
Amount: &types.Amount{
744743
Value: newValue,
@@ -800,7 +799,7 @@ func (b *Client) coinbaseTxOperation(
800799
NetworkIndex: &networkIndex,
801800
},
802801
Type: CoinbaseOpType,
803-
Status: SuccessStatus,
802+
Status: types.String(SuccessStatus),
804803
Metadata: metadata,
805804
}, nil
806805
}

bitcoin/client_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ func TestParseBlock(t *testing.T) {
735735
NetworkIndex: int64Pointer(0),
736736
},
737737
Type: CoinbaseOpType,
738-
Status: SuccessStatus,
738+
Status: types.String(SuccessStatus),
739739
Metadata: mustMarshalMap(&OperationMetadata{
740740
Coinbase: "04ffff001d02fd04",
741741
Sequence: 4294967295,
@@ -747,7 +747,7 @@ func TestParseBlock(t *testing.T) {
747747
NetworkIndex: int64Pointer(0),
748748
},
749749
Type: OutputOpType,
750-
Status: SuccessStatus,
750+
Status: types.String(SuccessStatus),
751751
Account: &types.AccountIdentifier{
752752
Address: "4104f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446aac", // nolint
753753
},
@@ -788,7 +788,7 @@ func TestParseBlock(t *testing.T) {
788788
NetworkIndex: int64Pointer(0),
789789
},
790790
Type: OutputOpType,
791-
Status: SuccessStatus,
791+
Status: types.String(SuccessStatus),
792792
Account: &types.AccountIdentifier{
793793
Address: "mmtKKnjqTPdkBnBMbNt5Yu2SCwpMaEshEL", // nolint
794794
},
@@ -820,7 +820,7 @@ func TestParseBlock(t *testing.T) {
820820
NetworkIndex: int64Pointer(1),
821821
},
822822
Type: OutputOpType,
823-
Status: SuccessStatus,
823+
Status: types.String(SuccessStatus),
824824
Account: &types.AccountIdentifier{
825825
Address: "4852fe372ff7534c16713b3146bbc1e86379c70bea4d5c02fb1fa0112980a081:1",
826826
},
@@ -928,7 +928,7 @@ func TestParseBlock(t *testing.T) {
928928
NetworkIndex: int64Pointer(0),
929929
},
930930
Type: CoinbaseOpType,
931-
Status: SuccessStatus,
931+
Status: types.String(SuccessStatus),
932932
Metadata: mustMarshalMap(&OperationMetadata{
933933
Coinbase: "044c86041b020602",
934934
Sequence: 4294967295,
@@ -940,7 +940,7 @@ func TestParseBlock(t *testing.T) {
940940
NetworkIndex: int64Pointer(0),
941941
},
942942
Type: OutputOpType,
943-
Status: SuccessStatus,
943+
Status: types.String(SuccessStatus),
944944
Account: &types.AccountIdentifier{
945945
Address: "34qkc2iac6RsyxZVfyE2S5U5WcRsbg2dpK",
946946
},
@@ -972,7 +972,7 @@ func TestParseBlock(t *testing.T) {
972972
NetworkIndex: int64Pointer(1),
973973
},
974974
Type: OutputOpType,
975-
Status: SuccessStatus,
975+
Status: types.String(SuccessStatus),
976976
Account: &types.AccountIdentifier{
977977
Address: "6a24aa21a9ed10109f4b82aa3ed7ec9d02a2a90246478b3308c8b85daf62fe501d58d05727a4",
978978
},
@@ -1007,7 +1007,7 @@ func TestParseBlock(t *testing.T) {
10071007
NetworkIndex: int64Pointer(0),
10081008
},
10091009
Type: InputOpType,
1010-
Status: SuccessStatus,
1010+
Status: types.String(SuccessStatus),
10111011
Amount: &types.Amount{
10121012
Value: "-5000000000",
10131013
Currency: MainnetCurrency,
@@ -1035,7 +1035,7 @@ func TestParseBlock(t *testing.T) {
10351035
NetworkIndex: int64Pointer(0),
10361036
},
10371037
Type: OutputOpType,
1038-
Status: SuccessStatus,
1038+
Status: types.String(SuccessStatus),
10391039
Account: &types.AccountIdentifier{
10401040
Address: "1JqDybm2nWTENrHvMyafbSXXtTk5Uv5QAn",
10411041
},
@@ -1067,7 +1067,7 @@ func TestParseBlock(t *testing.T) {
10671067
NetworkIndex: int64Pointer(1),
10681068
},
10691069
Type: OutputOpType,
1070-
Status: SuccessStatus,
1070+
Status: types.String(SuccessStatus),
10711071
Account: &types.AccountIdentifier{
10721072
Address: "1EYTGtG4LnFfiMvjJdsU7GMGCQvsRSjYhx",
10731073
},
@@ -1112,7 +1112,7 @@ func TestParseBlock(t *testing.T) {
11121112
NetworkIndex: int64Pointer(0),
11131113
},
11141114
Type: InputOpType,
1115-
Status: SuccessStatus,
1115+
Status: types.String(SuccessStatus),
11161116
Amount: &types.Amount{
11171117
Value: "-3467607",
11181118
Currency: MainnetCurrency,
@@ -1144,7 +1144,7 @@ func TestParseBlock(t *testing.T) {
11441144
NetworkIndex: int64Pointer(1),
11451145
},
11461146
Type: InputOpType,
1147-
Status: SuccessStatus,
1147+
Status: types.String(SuccessStatus),
11481148
Amount: &types.Amount{
11491149
Value: "0",
11501150
Currency: MainnetCurrency,
@@ -1172,7 +1172,7 @@ func TestParseBlock(t *testing.T) {
11721172
NetworkIndex: int64Pointer(2),
11731173
},
11741174
Type: InputOpType,
1175-
Status: SuccessStatus,
1175+
Status: types.String(SuccessStatus),
11761176
Amount: &types.Amount{
11771177
Value: "-556000000",
11781178
Currency: MainnetCurrency,
@@ -1200,7 +1200,7 @@ func TestParseBlock(t *testing.T) {
12001200
NetworkIndex: int64Pointer(0),
12011201
},
12021202
Type: OutputOpType,
1203-
Status: SuccessStatus,
1203+
Status: types.String(SuccessStatus),
12041204
Account: &types.AccountIdentifier{
12051205
Address: "76a914c398efa9c392ba6013c5e04ee729755ef7f58b3288ac",
12061206
},

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.13
55
require (
66
github.com/btcsuite/btcd v0.21.0-beta
77
github.com/btcsuite/btcutil v1.0.2
8-
github.com/coinbase/rosetta-sdk-go v0.5.9
8+
github.com/coinbase/rosetta-sdk-go v0.6.1
99
github.com/dgraph-io/badger/v2 v2.2007.2
1010
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
1111
github.com/stretchr/testify v1.6.1

go.sum

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJ
6262
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
6363
github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9/go.mod h1:1MxXX1Ux4x6mqPmjkUgTP1CdXIBXKX7T+Jk9Gxrmx+U=
6464
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
65-
github.com/coinbase/rosetta-sdk-go v0.5.9 h1:CuGQE3HFmYwdEACJnuOtVI9cofqPsGvq6FdFIzaOPKI=
66-
github.com/coinbase/rosetta-sdk-go v0.5.9/go.mod h1:xd4wYUhV3LkY78SPH8BUhc88rXfn2jYgN9BfiSjbcvM=
65+
github.com/coinbase/rosetta-sdk-go v0.6.1 h1:aOb5qstlX0uqP9HRC7wCY+YAZDzZbS2C/i3Qy/lR3xM=
66+
github.com/coinbase/rosetta-sdk-go v0.6.1/go.mod h1:t36UuaD4p2DSXaSH9IwMasZDJ7UPxt9cQi6alS5OPTo=
6767
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
6868
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
6969
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
@@ -97,11 +97,11 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
9797
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
9898
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
9999
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
100-
github.com/ethereum/go-ethereum v1.9.23 h1:SIKhg/z4Q7AbvqcxuPYvMxf36che/Rq/Pp0IdYEkbtw=
101-
github.com/ethereum/go-ethereum v1.9.23/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6wCncIu1hNwHpM=
100+
github.com/ethereum/go-ethereum v1.9.24 h1:6AK+ORt3EMDO+FTjzXy/AQwHMbu52J2nYHIjyQX9azQ=
101+
github.com/ethereum/go-ethereum v1.9.24/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6wCncIu1hNwHpM=
102102
github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
103-
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
104-
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
103+
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
104+
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
105105
github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
106106
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
107107
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
@@ -185,16 +185,11 @@ github.com/lucasjones/reggen v0.0.0-20180717132126-cdb49ff09d77 h1:6xiz3+ZczT3M4
185185
github.com/lucasjones/reggen v0.0.0-20180717132126-cdb49ff09d77/go.mod h1:5ELEyG+X8f+meRWHuqUOewBOhvHkl7M76pdGEansxW4=
186186
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
187187
github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
188-
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
189-
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
190-
github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw=
191-
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
188+
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
189+
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
192190
github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc=
193191
github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc=
194192
github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
195-
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
196-
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
197-
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
198193
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
199194
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
200195
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
@@ -268,6 +263,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
268263
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca/go.mod h1:u2MKkTVTVJWe5D1rCvame8WqhBd88EuIwODJZ1VHCPM=
269264
github.com/tidwall/gjson v1.6.1 h1:LRbvNuNuvAiISWg6gxLEFuCe72UKy5hDqhxW/8183ws=
270265
github.com/tidwall/gjson v1.6.1/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0=
266+
github.com/tidwall/gjson v1.6.3 h1:aHoiiem0dr7GHkW001T1SMTJ7X5PvyekH5WX0whWGnI=
267+
github.com/tidwall/gjson v1.6.3/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0=
271268
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
272269
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
273270
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
@@ -357,15 +354,13 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h
357354
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
358355
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
359356
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
360-
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
361357
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
362358
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
363359
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
364360
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
365361
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
366362
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
367363
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
368-
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
369364
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
370365
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
371366
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

indexer/indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func (i *Indexer) Sync(ctx context.Context) error {
255255
// If previously processed blocks exist in storage, they are fetched.
256256
// Otherwise, none are provided to the cache (the syncer will not attempt
257257
// a reorg if the cache is empty).
258-
pastBlocks := i.blockStorage.CreateBlockCache(ctx)
258+
pastBlocks := i.blockStorage.CreateBlockCache(ctx, syncer.DefaultPastBlockLimit)
259259

260260
syncer := syncer.New(
261261
i.network,

indexer/indexer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func TestIndexer_Transactions(t *testing.T) {
286286
Index: 0,
287287
NetworkIndex: &index0,
288288
},
289-
Status: bitcoin.SuccessStatus,
289+
Status: types.String(bitcoin.SuccessStatus),
290290
Type: bitcoin.OutputOpType,
291291
Account: &types.AccountIdentifier{
292292
Address: rawHash,
@@ -505,7 +505,7 @@ func TestIndexer_Reorg(t *testing.T) {
505505
Index: 0,
506506
NetworkIndex: &index0,
507507
},
508-
Status: bitcoin.SuccessStatus,
508+
Status: types.String(bitcoin.SuccessStatus),
509509
Type: bitcoin.OutputOpType,
510510
Account: &types.AccountIdentifier{
511511
Address: rawHash,

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func main() {
157157
services.HistoricalBalanceLookup,
158158
[]*types.NetworkIdentifier{cfg.Network},
159159
nil,
160+
services.MempoolCoins,
160161
)
161162
if err != nil {
162163
logger.Fatalw("unable to create new server asserter", "error", err)

services/account_service.go

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,7 @@ func (s *AccountAPIService) AccountBalance(
4949
return nil, wrapErr(ErrUnavailableOffline, nil)
5050
}
5151

52-
// If we are fetching the current balance,
53-
// return all coins for an address and calculate
54-
// the balance from those coins.
55-
if request.BlockIdentifier == nil {
56-
coins, block, err := s.i.GetCoins(ctx, request.AccountIdentifier)
57-
if err != nil {
58-
return nil, wrapErr(ErrUnableToGetCoins, err)
59-
}
60-
61-
balance := "0"
62-
for _, coin := range coins {
63-
balance, err = types.AddValues(balance, coin.Amount.Value)
64-
if err != nil {
65-
return nil, wrapErr(ErrUnableToParseIntermediateResult, err)
66-
}
67-
}
68-
69-
return &types.AccountBalanceResponse{
70-
BlockIdentifier: block,
71-
Coins: coins,
72-
Balances: []*types.Amount{
73-
{
74-
Value: balance,
75-
Currency: s.config.Currency,
76-
},
77-
},
78-
}, nil
79-
}
52+
// TODO: filter balances by request currencies
8053

8154
// If we are fetching a historical balance,
8255
// use balance storage and don't return coins.
@@ -97,3 +70,31 @@ func (s *AccountAPIService) AccountBalance(
9770
},
9871
}, nil
9972
}
73+
74+
// AccountCoins implements /account/coins.
75+
func (s *AccountAPIService) AccountCoins(
76+
ctx context.Context,
77+
request *types.AccountCoinsRequest,
78+
) (*types.AccountCoinsResponse, *types.Error) {
79+
if s.config.Mode != configuration.Online {
80+
return nil, wrapErr(ErrUnavailableOffline, nil)
81+
}
82+
83+
// TODO: filter coins by request currencies
84+
85+
// TODO: support include_mempool query
86+
// https://github.com/coinbase/rosetta-bitcoin/issues/36#issuecomment-724992022
87+
// Once mempoolcoins are supported also change the bool service/types.go:MempoolCoins to true
88+
89+
coins, block, err := s.i.GetCoins(ctx, request.AccountIdentifier)
90+
if err != nil {
91+
return nil, wrapErr(ErrUnableToGetCoins, err)
92+
}
93+
94+
result := &types.AccountCoinsResponse{
95+
BlockIdentifier: block,
96+
Coins: coins,
97+
}
98+
99+
return result, nil
100+
}

0 commit comments

Comments
 (0)