/
rpcclient.go
634 lines (553 loc) · 20.3 KB
/
rpcclient.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
// Copyright (c) 2018-2019, The Decred developers
// Copyright (c) 2017, Jonathan Chappelow
// See LICENSE for details.
package rpcutils
import (
"context"
"encoding/hex"
"errors"
"fmt"
"io/ioutil"
"strconv"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/chaincfg/v2"
"github.com/decred/dcrd/dcrutil/v2"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types"
"github.com/decred/dcrd/rpcclient/v4"
"github.com/decred/dcrd/wire"
apitypes "github.com/decred/dcrdata/api/types/v4"
"github.com/decred/dcrdata/semver"
"github.com/decred/dcrdata/txhelpers/v3"
)
// Any of the following dcrd RPC API versions are deemed compatible with
// dcrdata.
var compatibleChainServerAPIs = []semver.Semver{
semver.NewSemver(6, 0, 0),
}
var (
zeroHash = chainhash.Hash{}
zeroHashStringBytes = []byte(chainhash.Hash{}.String())
maxAncestorChainLength = 8192
ErrAncestorAtGenesis = errors.New("no ancestor: at genesis")
ErrAncestorMaxChainLength = errors.New("no ancestor: max chain length reached")
)
// ConnectNodeRPC attempts to create a new websocket connection to a dcrd node,
// with the given credentials and optional notification handlers.
func ConnectNodeRPC(host, user, pass, cert string, disableTLS, disableReconnect bool,
ntfnHandlers ...*rpcclient.NotificationHandlers) (*rpcclient.Client, semver.Semver, error) {
var dcrdCerts []byte
var err error
var nodeVer semver.Semver
if !disableTLS {
dcrdCerts, err = ioutil.ReadFile(cert)
if err != nil {
log.Errorf("Failed to read dcrd cert file at %s: %s\n",
cert, err.Error())
return nil, nodeVer, err
}
log.Debugf("Attempting to connect to dcrd RPC %s as user %s "+
"using certificate located in %s",
host, user, cert)
} else {
log.Debugf("Attempting to connect to dcrd RPC %s as user %s (no TLS)",
host, user)
}
connCfgDaemon := &rpcclient.ConnConfig{
Host: host,
Endpoint: "ws", // websocket
User: user,
Pass: pass,
Certificates: dcrdCerts,
DisableTLS: disableTLS,
DisableAutoReconnect: disableReconnect,
}
var ntfnHdlrs *rpcclient.NotificationHandlers
if len(ntfnHandlers) > 0 {
if len(ntfnHandlers) > 1 {
return nil, nodeVer, fmt.Errorf("invalid notification handler argument")
}
ntfnHdlrs = ntfnHandlers[0]
}
dcrdClient, err := rpcclient.New(connCfgDaemon, ntfnHdlrs)
if err != nil {
return nil, nodeVer, fmt.Errorf("Failed to start dcrd RPC client: %s", err.Error())
}
// Ensure the RPC server has a compatible API version.
ver, err := dcrdClient.Version()
if err != nil {
log.Error("Unable to get RPC version: ", err)
return nil, nodeVer, fmt.Errorf("unable to get node RPC version")
}
dcrdVer := ver["dcrdjsonrpcapi"]
nodeVer = semver.NewSemver(dcrdVer.Major, dcrdVer.Minor, dcrdVer.Patch)
// Check if the dcrd RPC API version is compatible with dcrdata.
isApiCompat := semver.AnyCompatible(compatibleChainServerAPIs, nodeVer)
if !isApiCompat {
return nil, nodeVer, fmt.Errorf("Node JSON-RPC server does not have "+
"a compatible API version. Advertises %v but requires one of: %v",
nodeVer, compatibleChainServerAPIs)
}
return dcrdClient, nodeVer, nil
}
// BuildBlockHeaderVerbose creates a *chainjson.GetBlockHeaderVerboseResult from
// an input *wire.BlockHeader and current best block height, which is used to
// compute confirmations. The next block hash may optionally be provided.
func BuildBlockHeaderVerbose(header *wire.BlockHeader, params *chaincfg.Params,
currentHeight int64, nextHash ...string) *chainjson.GetBlockHeaderVerboseResult {
if header == nil {
return nil
}
diffRatio := txhelpers.GetDifficultyRatio(header.Bits, params)
var next string
if len(nextHash) > 0 {
next = nextHash[0]
}
blockHeaderResult := chainjson.GetBlockHeaderVerboseResult{
Hash: header.BlockHash().String(),
Confirmations: currentHeight - int64(header.Height),
Version: header.Version,
PreviousHash: header.PrevBlock.String(),
MerkleRoot: header.MerkleRoot.String(),
StakeRoot: header.StakeRoot.String(),
VoteBits: header.VoteBits,
FinalState: hex.EncodeToString(header.FinalState[:]),
Voters: header.Voters,
FreshStake: header.FreshStake,
Revocations: header.Revocations,
PoolSize: header.PoolSize,
Bits: strconv.FormatInt(int64(header.Bits), 16),
SBits: dcrutil.Amount(header.SBits).ToCoin(),
Height: header.Height,
Size: header.Size,
Time: header.Timestamp.Unix(),
Nonce: header.Nonce,
Difficulty: diffRatio,
// Cannot get ChainWork from the wire.BlockHeader
NextHash: next,
}
return &blockHeaderResult
}
// GetBlockHeaderVerbose creates a *chainjson.GetBlockHeaderVerboseResult for the
// block at height idx via an RPC connection to a chain server.
func GetBlockHeaderVerbose(client BlockFetcher, idx int64) *chainjson.GetBlockHeaderVerboseResult {
blockhash, err := client.GetBlockHash(idx)
if err != nil {
log.Errorf("GetBlockHash(%d) failed: %v", idx, err)
return nil
}
blockHeaderVerbose, err := client.GetBlockHeaderVerbose(blockhash)
if err != nil {
log.Errorf("GetBlockHeaderVerbose(%v) failed: %v", blockhash, err)
return nil
}
return blockHeaderVerbose
}
// GetBlockHeaderVerboseByString creates a *chainjson.GetBlockHeaderVerboseResult
// for the block specified by hash via an RPC connection to a chain server.
func GetBlockHeaderVerboseByString(client BlockFetcher, hash string) *chainjson.GetBlockHeaderVerboseResult {
blockhash, err := chainhash.NewHashFromStr(hash)
if err != nil {
log.Errorf("Invalid block hash %s: %v", blockhash, err)
return nil
}
blockHeaderVerbose, err := client.GetBlockHeaderVerbose(blockhash)
if err != nil {
log.Errorf("GetBlockHeaderVerbose(%v) failed: %v", blockhash, err)
return nil
}
return blockHeaderVerbose
}
// GetBlockVerbose creates a *chainjson.GetBlockVerboseResult for the block index
// specified by idx via an RPC connection to a chain server.
func GetBlockVerbose(client *rpcclient.Client, idx int64, verboseTx bool) *chainjson.GetBlockVerboseResult {
blockhash, err := client.GetBlockHash(idx)
if err != nil {
log.Errorf("GetBlockHash(%d) failed: %v", idx, err)
return nil
}
blockVerbose, err := client.GetBlockVerbose(blockhash, verboseTx)
if err != nil {
log.Errorf("GetBlockVerbose(%v) failed: %v", blockhash, err)
return nil
}
return blockVerbose
}
// GetBlockVerboseByHash creates a *chainjson.GetBlockVerboseResult for the
// specified block hash via an RPC connection to a chain server.
func GetBlockVerboseByHash(client *rpcclient.Client, hash string, verboseTx bool) *chainjson.GetBlockVerboseResult {
blockhash, err := chainhash.NewHashFromStr(hash)
if err != nil {
log.Errorf("Invalid block hash %s", hash)
return nil
}
blockVerbose, err := client.GetBlockVerbose(blockhash, verboseTx)
if err != nil {
log.Errorf("GetBlockVerbose(%v) failed: %v", blockhash, err)
return nil
}
return blockVerbose
}
// GetStakeDiffEstimates combines the results of EstimateStakeDiff and
// GetStakeDifficulty into a *apitypes.StakeDiff.
func GetStakeDiffEstimates(client *rpcclient.Client) *apitypes.StakeDiff {
stakeDiff, err := client.GetStakeDifficulty()
if err != nil {
return nil
}
estStakeDiff, err := client.EstimateStakeDiff(nil)
if err != nil {
return nil
}
stakeDiffEstimates := apitypes.StakeDiff{
GetStakeDifficultyResult: chainjson.GetStakeDifficultyResult{
CurrentStakeDifficulty: stakeDiff.CurrentStakeDifficulty,
NextStakeDifficulty: stakeDiff.NextStakeDifficulty,
},
Estimates: *estStakeDiff,
}
return &stakeDiffEstimates
}
// GetBlock gets a block at the given height from a chain server.
func GetBlock(ind int64, client BlockFetcher) (*dcrutil.Block, *chainhash.Hash, error) {
blockhash, err := client.GetBlockHash(ind)
if err != nil {
return nil, nil, fmt.Errorf("GetBlockHash(%d) failed: %v", ind, err)
}
msgBlock, err := client.GetBlock(blockhash)
if err != nil {
return nil, blockhash,
fmt.Errorf("GetBlock failed (%s): %v", blockhash, err)
}
block := dcrutil.NewBlock(msgBlock)
return block, blockhash, nil
}
// GetBlockByHash gets the block with the given hash from a chain server.
func GetBlockByHash(blockhash *chainhash.Hash, client BlockFetcher) (*dcrutil.Block, error) {
msgBlock, err := client.GetBlock(blockhash)
if err != nil {
return nil, fmt.Errorf("GetBlock failed (%s): %v", blockhash, err)
}
block := dcrutil.NewBlock(msgBlock)
return block, nil
}
// SideChains gets a slice of known side chain tips. This corresponds to the
// results of the getchaintips node RPC where the block tip "status" is either
// "valid-headers" or "valid-fork".
func SideChains(client *rpcclient.Client) ([]chainjson.GetChainTipsResult, error) {
tips, err := client.GetChainTips()
if err != nil {
return nil, err
}
return sideChainTips(tips), nil
}
func sideChainTips(allTips []chainjson.GetChainTipsResult) (sideTips []chainjson.GetChainTipsResult) {
for i := range allTips {
switch allTips[i].Status {
case "valid-headers", "valid-fork":
sideTips = append(sideTips, allTips[i])
}
}
return
}
// SideChainFull gets all of the blocks in the side chain with the specified tip
// block hash. The first block in the slice is the lowest height block in the
// side chain, and its previous block is the main/side common ancestor, which is
// not included in the slice since it is main chain. The last block in the slice
// is thus the side chain tip.
func SideChainFull(client BlockFetcher, tipHash string) ([]string, error) {
// Do not assume specified tip hash is even side chain.
var sideChain []string
hash := tipHash
for {
header := GetBlockHeaderVerboseByString(client, hash)
if header == nil {
return nil, fmt.Errorf("GetBlockHeaderVerboseByString failed for block %s", hash)
}
// Main chain blocks have Confirmations != -1.
if header.Confirmations != -1 {
// The passed block is main chain, not a side chain tip.
if hash == tipHash {
return nil, fmt.Errorf("tip block is not on a side chain")
}
// This previous block is the main/side common ancestor.
break
}
// This was another side chain block.
sideChain = append(sideChain, hash)
// On to previous block
hash = header.PreviousHash
}
// Reverse side chain order so that last element is tip.
reverseStringSlice(sideChain)
return sideChain, nil
}
func reverseStringSlice(s []string) {
N := len(s)
for i := 0; i <= (N/2)-1; i++ {
j := N - 1 - i
s[i], s[j] = s[j], s[i]
}
}
// GetTransactionVerboseByID get a transaction by transaction id
func GetTransactionVerboseByID(client txhelpers.VerboseTransactionGetter, txhash *chainhash.Hash) (*chainjson.TxRawResult, error) {
txraw, err := client.GetRawTransactionVerbose(txhash)
if err != nil {
log.Errorf("GetRawTransactionVerbose failed for: %v", txhash)
return nil, err
}
return txraw, nil
}
// SearchRawTransaction fetch transactions pertaining to an address.
func SearchRawTransaction(client *rpcclient.Client, params *chaincfg.Params, count int, address string) ([]*chainjson.SearchRawTransactionsResult, error) {
addr, err := dcrutil.DecodeAddress(address, params)
if err != nil {
log.Infof("Invalid address %s: %v", address, err)
return nil, err
}
//change the 1000 000 number demo for now
txs, err := client.SearchRawTransactionsVerbose(addr, 0, count,
true, true, nil)
if err != nil {
log.Warnf("SearchRawTransaction failed for address %s: %v", addr, err)
}
return txs, nil
}
// CommonAncestor attempts to determine the common ancestor block for two chains
// specified by the hash of the chain tip block. The full chains from the tips
// back to but not including the common ancestor are also returned. The first
// element in the chain slices is the lowest block following the common
// ancestor, while the last element is the chain tip. The common ancestor will
// never by one of the chain tips. Thus, if one of the chain tips is on the
// other chain, that block will be shared between the two chains, and the common
// ancestor will be the previous block. However, the intended use of this
// function is to find a common ancestor for two chains with no common blocks.
func CommonAncestor(client BlockFetcher, hashA, hashB chainhash.Hash) (*chainhash.Hash, []chainhash.Hash, []chainhash.Hash, error) {
if client == nil {
return nil, nil, nil, errors.New("nil RPC client")
}
var length int
var chainA, chainB []chainhash.Hash
for {
if length >= maxAncestorChainLength {
return nil, nil, nil, ErrAncestorMaxChainLength
}
// Chain A
blockA, err := client.GetBlock(&hashA)
if err != nil {
return nil, nil, nil, fmt.Errorf("Failed to get block %v: %v", hashA, err)
}
heightA := blockA.Header.Height
// Chain B
blockB, err := client.GetBlock(&hashB)
if err != nil {
return nil, nil, nil, fmt.Errorf("Failed to get block %v: %v", hashB, err)
}
heightB := blockB.Header.Height
// Reach the same height on both chains before checking the loop
// termination condition. At least one previous block for each chain
// must be used, so that a chain tip block will not be considered a
// common ancestor and it will instead be added to a chain slice.
if heightA > heightB {
chainA = append([]chainhash.Hash{hashA}, chainA...)
length++
hashA = blockA.Header.PrevBlock
continue
}
if heightB > heightA {
chainB = append([]chainhash.Hash{hashB}, chainB...)
length++
hashB = blockB.Header.PrevBlock
continue
}
// Assert heightB == heightA
if heightB != heightA {
panic("you broke the code")
}
chainA = append([]chainhash.Hash{hashA}, chainA...)
chainB = append([]chainhash.Hash{hashB}, chainB...)
length++
// We are at genesis if the previous block is the zero hash.
if blockA.Header.PrevBlock == zeroHash {
return nil, chainA, chainB, ErrAncestorAtGenesis // no common ancestor, but the same block
}
hashA = blockA.Header.PrevBlock
hashB = blockB.Header.PrevBlock
// break here rather than for condition so inputs with equal hashes get
// handled properly (with ancestor as previous block and chains
// including the input blocks.)
if hashA == hashB {
break // hashA(==hashB) is the common ancestor.
}
}
// hashA == hashB
return &hashA, chainA, chainB, nil
}
// BlockHashGetter is an interface implementing GetBlockHash to retrieve a block
// hash from a height.
type BlockHashGetter interface {
GetBlockHash(int64) (*chainhash.Hash, error)
}
// OrphanedTipLength finds a common ancestor by iterating block heights
// backwards until a common block hash is found. Unlike CommonAncestor, an
// orphaned DB tip whose corresponding block is not known to dcrd will not cause
// an error. The number of blocks that have been orphaned is returned.
// Realistically, this should rarely be anything but 0 or 1, but no limits are
// placed here on the number of blocks checked.
func OrphanedTipLength(ctx context.Context, client BlockHashGetter,
tipHeight int64, hashFunc func(int64) (string, error)) (int64, error) {
commonHeight := tipHeight
var dbHash string
var err error
var dcrdHash *chainhash.Hash
for {
// Since there are no limits on the number of blocks scanned, allow
// cancellation for a clean exit.
select {
case <-ctx.Done():
return 0, nil
default:
}
dbHash, err = hashFunc(commonHeight)
if err != nil {
return -1, fmt.Errorf("Unable to retrieve block at height %d: %v", commonHeight, err)
}
dcrdHash, err = client.GetBlockHash(commonHeight)
if err != nil {
return -1, fmt.Errorf("Unable to retrieve dcrd block at height %d: %v", commonHeight, err)
}
if dcrdHash.String() == dbHash {
break
}
commonHeight--
if commonHeight < 0 {
return -1, fmt.Errorf("Unable to find a common ancestor")
}
// Reorgs are soft-limited to depth 6 by dcrd. More than six blocks without
// a match probably indicates an issue.
if commonHeight-tipHeight == 7 {
log.Warnf("No common ancestor within 6 blocks. This is abnormal")
}
}
return tipHeight - commonHeight, nil
}
// GetChainWork fetches the chainjson.BlockHeaderVerbose and returns only the
// ChainWork field as a string.
func GetChainWork(client BlockFetcher, hash *chainhash.Hash) (string, error) {
header, err := client.GetBlockHeaderVerbose(hash)
if err != nil {
return "", err
}
return header.ChainWork, nil
}
// MempoolAddressChecker is an interface implementing UnconfirmedTxnsForAddress
type MempoolAddressChecker interface {
UnconfirmedTxnsForAddress(address string) (*txhelpers.AddressOutpoints, int64, error)
}
type mempoolAddressChecker struct {
client *rpcclient.Client
params *chaincfg.Params
}
// UnconfirmedTxnsForAddress implements MempoolAddressChecker.
func (m *mempoolAddressChecker) UnconfirmedTxnsForAddress(address string) (*txhelpers.AddressOutpoints, int64, error) {
return UnconfirmedTxnsForAddress(m.client, address, m.params)
}
// NewMempoolAddressChecker creates a new MempoolAddressChecker from an RPC
// client for the given network.
func NewMempoolAddressChecker(client *rpcclient.Client, params *chaincfg.Params) MempoolAddressChecker {
return &mempoolAddressChecker{client, params}
}
// UnconfirmedTxnsForAddress returns the chainhash.Hash of all transactions in
// mempool that (1) pay to the given address, or (2) spend a previous outpoint
// that paid to the address.
func UnconfirmedTxnsForAddress(client *rpcclient.Client, address string, params *chaincfg.Params) (*txhelpers.AddressOutpoints, int64, error) {
// Mempool transactions
var numUnconfirmed int64
mempoolTxns, err := client.GetRawMempoolVerbose(chainjson.GRMAll)
if err != nil {
log.Warnf("GetRawMempool failed for address %s: %v", address, err)
return nil, numUnconfirmed, err
}
// Check each transaction for involvement with provided address.
addressOutpoints := txhelpers.NewAddressOutpoints(address)
for hash, tx := range mempoolTxns {
// Transaction details from dcrd
txhash, err1 := chainhash.NewHashFromStr(hash)
if err1 != nil {
log.Errorf("Invalid transaction hash %s", hash)
return addressOutpoints, 0, err1
}
Tx, err1 := client.GetRawTransaction(txhash)
if err1 != nil {
log.Warnf("Unable to GetRawTransaction(%s): %v", hash, err1)
err = err1
continue
}
// Scan transaction for inputs/outputs involving the address of interest
outpoints, prevouts, prevTxns := txhelpers.TxInvolvesAddress(Tx.MsgTx(),
address, client, params)
if len(outpoints) == 0 && len(prevouts) == 0 {
continue
}
// Update previous outpoint txn slice with mempool time
for f := range prevTxns {
prevTxns[f].MemPoolTime = tx.Time
}
// Add present transaction to previous outpoint txn slice
numUnconfirmed++
thisTxUnconfirmed := &txhelpers.TxWithBlockData{
Tx: Tx.MsgTx(),
MemPoolTime: tx.Time,
}
prevTxns = append(prevTxns, thisTxUnconfirmed)
// Merge the I/Os and the transactions into results
addressOutpoints.Update(prevTxns, outpoints, prevouts)
}
return addressOutpoints, numUnconfirmed, err
}
// APITransaction uses the RPC client to retrieve the specified transaction, and
// convert the data into a *apitypes.Tx.
func APITransaction(client txhelpers.VerboseTransactionGetter, txid *chainhash.Hash) (tx *apitypes.Tx, hex string, err error) {
txraw, err := GetTransactionVerboseByID(client, txid)
if err != nil {
err = fmt.Errorf("APITransaction failed for %v: %v", txid, err)
return
}
hex = txraw.Hex
tx = new(apitypes.Tx)
tx.TxID = txraw.Txid
tx.Size = int32(len(hex) / 2)
tx.Version = txraw.Version
tx.Locktime = txraw.LockTime
tx.Expiry = txraw.Expiry
tx.Vin = make([]chainjson.Vin, len(txraw.Vin))
copy(tx.Vin, txraw.Vin)
tx.Vout = make([]apitypes.Vout, len(txraw.Vout))
for i := range txraw.Vout {
tx.Vout[i].Value = txraw.Vout[i].Value
tx.Vout[i].N = txraw.Vout[i].N
tx.Vout[i].Version = txraw.Vout[i].Version
spk := &tx.Vout[i].ScriptPubKeyDecoded
spkRaw := &txraw.Vout[i].ScriptPubKey
spk.Asm = spkRaw.Asm
spk.Hex = spkRaw.Hex
spk.ReqSigs = spkRaw.ReqSigs
spk.Type = spkRaw.Type
spk.Addresses = make([]string, len(spkRaw.Addresses))
for j := range spkRaw.Addresses {
spk.Addresses[j] = spkRaw.Addresses[j]
}
if spkRaw.CommitAmt != nil {
spk.CommitAmt = new(float64)
*spk.CommitAmt = *spkRaw.CommitAmt
}
}
tx.Confirmations = txraw.Confirmations
// BlockID
tx.Block = new(apitypes.BlockID)
tx.Block.BlockHash = txraw.BlockHash
tx.Block.BlockHeight = txraw.BlockHeight
tx.Block.BlockIndex = txraw.BlockIndex
tx.Block.Time = txraw.Time
tx.Block.BlockTime = txraw.Blocktime
return
}