From 526b7534d6028f59b0f99a2a3e6f8e95a25d06cb Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Mon, 30 Apr 2018 15:07:31 +0200 Subject: [PATCH] Revert the order of transactions in socket.io interface --- server/socketio.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/socketio.go b/server/socketio.go index f7cb7007..08c9535b 100644 --- a/server/socketio.go +++ b/server/socketio.go @@ -249,17 +249,20 @@ func unmarshalGetAddressRequest(params []byte) (addr []string, opts addrOpts, er return } -func uniqueTxids(txids []string) []string { - uniqueTxids := make([]string, 0, len(txids)) +// bitcore returns txids from the newest to the oldest, we have to revert the order +func uniqueTxidsInReverse(txids []string) []string { + i := len(txids) + ut := make([]string, i) txidsMap := make(map[string]struct{}) for _, txid := range txids { _, e := txidsMap[txid] if !e { - uniqueTxids = append(uniqueTxids, txid) + i-- + ut[i] = txid txidsMap[txid] = struct{}{} } } - return uniqueTxids + return ut[i:] } type resultAddressTxids struct { @@ -296,7 +299,7 @@ func (s *SocketIoServer) getAddressTxids(addr []string, opts *addrOpts) (res res return res, err } } - res.Result = uniqueTxids(txids) + res.Result = uniqueTxidsInReverse(txids) return res, nil }