From 511eb6aa6859fff8297402e1b48801e7ea814fc4 Mon Sep 17 00:00:00 2001 From: Liquid Date: Thu, 20 Oct 2022 08:57:13 -0500 Subject: [PATCH] Use vout addr array instead not array test dumb Push remove array select bytes slice bytes set byte string Fix syntax proper conversion proper slice add err remove byteaddr slice typecast adjust err slice ... select handle err add back error and ignore reset just cause its bugging out adjust redo type cast remove brackets fix spelling array cast try diff cast inttobytearray test shit syntax Reset fix import fix import add to worker fix naming use right var change set addr simplify change logic --- api/worker.go | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/api/worker.go b/api/worker.go index 2fe8c482..3b1ae6fc 100644 --- a/api/worker.go +++ b/api/worker.go @@ -3,7 +3,6 @@ package api import ( "blockbook/bchain" "blockbook/bchain/coins/eth" - "blockbook/bchain/coins/pivx" "blockbook/common" "blockbook/db" "bytes" @@ -54,6 +53,17 @@ func (w *Worker) getAddressesFromVout(vout *bchain.Vout) (bchain.AddressDescript return addrDesc, a, s, err } +// returns true if scriptPubKey is P2CS +func isP2CS(addrs []string) bool { + if len(addrs) != 2 { + return false + } + // dirty hack (to remove multisig false positives) + // !TODO: implement flag in Vin and Vout objects + return (len(addrs[0]) > 0 && + (addrs[0][0:1] == "S" || addrs[0][0:1] == "W")) +} + // setSpendingTxToVout is helper function, that finds transaction that spent given output and sets it to the output // there is no direct index for the operation, it must be found using addresses -> txaddresses -> tx func (w *Worker) setSpendingTxToVout(vout *Vout, txid string, height uint32) error { @@ -878,9 +888,13 @@ func (w *Worker) getAddrDescUtxo(addrDesc bchain.AddressDescriptor, ba *db.AddrB vad, err := w.chainParser.GetAddrDescFromVout(vout) if err == nil && bytes.Equal(addrDesc, vad) { // report only outpoints that are not spent in mempool + stakeContract := false _, e := spentInMempool[bchainTx.Txid+strconv.Itoa(i)] + addr := vout.ScriptPubKey.Addresses if !e { - stakeContract := pivx.IsP2CSScript(addrDesc) + if isP2CS(addr) { + stakeContract = true + } r = append(r, Utxo{ Txid: bchainTx.Txid, Vout: int32(i), @@ -919,7 +933,20 @@ func (w *Worker) getAddrDescUtxo(addrDesc bchain.AddressDescriptor, ba *db.AddrB if err != nil { return nil, err } - stakeContract := pivx.IsP2CSScript(addrDesc) + stakeContract := false + ta, err := w.db.GetTxAddresses(txid) + if err != nil { + return nil, err + } + addr, _, err := ta.Outputs[utxo.Vout].Addresses(w.chainParser) + if err != nil { + return nil, err + } + if len(addr) > 1 { + if isP2CS(addr) { + stakeContract = true + } + } _, e := spentInMempool[txid+strconv.Itoa(int(utxo.Vout))] if !e { r = append(r, Utxo{