From 3f75dc2c7edf0c511df3c6e7beaf50ab250c96d4 Mon Sep 17 00:00:00 2001 From: Julian Meyer Date: Mon, 22 Jul 2019 16:34:52 -0700 Subject: [PATCH 1/2] Sort transactions by index in block as well as height --- bitcoin/phored/wallet.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/bitcoin/phored/wallet.go b/bitcoin/phored/wallet.go index 0cadd19373..e21f6f968f 100644 --- a/bitcoin/phored/wallet.go +++ b/bitcoin/phored/wallet.go @@ -1129,6 +1129,7 @@ type ReceivedTx struct { tx wire.MsgTx blockHeight int32 blockTime time.Time + blockIndex int32 } // RetrieveTransactions fetches transactions from the rpc server and stores them into the database @@ -1161,7 +1162,8 @@ func (w *RPCWallet) RetrieveTransactions() error { transactions = append(transactions, w.receiveTransactions(scriptAddresses, false)...) sort.SliceStable(transactions, func(i, j int) bool { - return transactions[i].blockHeight < transactions[j].blockHeight + return transactions[i].blockHeight < transactions[j].blockHeight || + (transactions[i].blockHeight == transactions[j].blockHeight && transactions[i].blockIndex < transactions[j].blockIndex) }) for _, tx := range transactions { @@ -1240,7 +1242,26 @@ func (w *RPCWallet) receiveTransactions(addrs []btc.Address, lookAhead bool) []R continue } - transactions = append(transactions, ReceivedTx{transaction, int32(block.Height), time.Unix(block.Time, 0)}) + // replace this by sending the index of the transaction in the block + index := int32(-1) + + for i, transactionHex := range block.Tx { + if transactionHex == transaction.TxHash().String() { + index = int32(i) + } + } + + if index == -1 { + log.Errorf("could not find transaction in block") + continue + } + + transactions = append(transactions, ReceivedTx{ + tx: transaction, + blockHeight: int32(block.Height), + blockTime: time.Unix(block.Time, 0), + blockIndex: index, + }) } } return transactions From 9c410a6f4ea9476efe09fc8935a5c242f3882f60 Mon Sep 17 00:00:00 2001 From: anchaj Date: Tue, 23 Jul 2019 01:53:20 +0200 Subject: [PATCH 2/2] Bump version. --- core/core.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/core.go b/core/core.go index 97bd8d4227..143efc147f 100644 --- a/core/core.go +++ b/core/core.go @@ -29,7 +29,7 @@ import ( ) var ( - VERSION = "2.0.1" + VERSION = "2.0.2" USERAGENT = "/Phore-Marketplace-go:" + VERSION + "/" )