From 0612d020654c88d2eb87d43dfdd7709e90654771 Mon Sep 17 00:00:00 2001 From: PeterL73 Date: Sat, 29 Oct 2022 20:06:12 +0200 Subject: [PATCH 1/2] add OP_CHECKCOLDSTAKEVERIFY_LOF --- bchain/coins/pivx/pivxparser.go | 5 +++-- db/rocksdb.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bchain/coins/pivx/pivxparser.go b/bchain/coins/pivx/pivxparser.go index 874bca81..c361f66f 100644 --- a/bchain/coins/pivx/pivxparser.go +++ b/bchain/coins/pivx/pivxparser.go @@ -39,7 +39,8 @@ const ( OP_CHECKSIG = 0xac OP_ZEROCOINMINT = 0xc1 OP_ZEROCOINSPEND = 0xc2 - OP_CHECKCOLDSTAKEVERIFY = 0xd1 + OP_CHECKCOLDSTAKEVERIFY_LOF = 0xd1 + OP_CHECKCOLDSTAKEVERIFY = 0xd2 // Labels ZCMINT_LABEL = "Zerocoin Mint" @@ -340,7 +341,7 @@ func IsP2CSScript(signatureScript []byte) bool { signatureScript[1] == OP_HASH160 && signatureScript[2] == OP_ROT && signatureScript[3] == OP_IF && - signatureScript[4] == OP_CHECKCOLDSTAKEVERIFY && + (signatureScript[4] == OP_CHECKCOLDSTAKEVERIFY || signatureScript[4] == OP_CHECKCOLDSTAKEVERIFY_LOF) && signatureScript[5] == 0x14 && signatureScript[26] == OP_ELSE && signatureScript[27] == 0x14 && diff --git a/db/rocksdb.go b/db/rocksdb.go index 222a8b52..85a908bf 100644 --- a/db/rocksdb.go +++ b/db/rocksdb.go @@ -524,10 +524,11 @@ func (d *RocksDB) GetAndResetConnectBlockStats() string { } // PIVX -const OP_CHECKCOLDSTAKEVERIFY = 0xd1 +const OP_CHECKCOLDSTAKEVERIFY_LOF = 0xd1 +const OP_CHECKCOLDSTAKEVERIFY = 0xd2 func isPayToColdStake(signatureScript []byte) bool { - return len(signatureScript) > 50 && signatureScript[4] == OP_CHECKCOLDSTAKEVERIFY + return len(signatureScript) > 50 && (signatureScript[4] == OP_CHECKCOLDSTAKEVERIFY || signatureScript[4] == OP_CHECKCOLDSTAKEVERIFY_LOF) } func getOwnerFromP2CS(signatureScript []byte) ([]byte, error) { From 70b81a837733bd679bec23b8ac46a0fbbfd1d26c Mon Sep 17 00:00:00 2001 From: PeterL73 Date: Mon, 31 Oct 2022 11:17:23 +0100 Subject: [PATCH 2/2] check ScriptPubKey for cold staking contract --- api/worker.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/api/worker.go b/api/worker.go index 2fe8c482..1a6c942c 100644 --- a/api/worker.go +++ b/api/worker.go @@ -8,6 +8,7 @@ import ( "blockbook/db" "bytes" "encoding/json" + "encoding/hex" "fmt" "math" "math/big" @@ -880,7 +881,10 @@ func (w *Worker) getAddrDescUtxo(addrDesc bchain.AddressDescriptor, ba *db.AddrB // report only outpoints that are not spent in mempool _, e := spentInMempool[bchainTx.Txid+strconv.Itoa(i)] if !e { - stakeContract := pivx.IsP2CSScript(addrDesc) + // Get ScriptPubKey for vout and check if it is a cold staking contract + script, _ := hex.DecodeString(bchainTx.Vout[i].ScriptPubKey.Hex) + stakeContract := pivx.IsP2CSScript(script) + r = append(r, Utxo{ Txid: bchainTx.Txid, Vout: int32(i), @@ -919,9 +923,13 @@ func (w *Worker) getAddrDescUtxo(addrDesc bchain.AddressDescriptor, ba *db.AddrB if err != nil { return nil, err } - stakeContract := pivx.IsP2CSScript(addrDesc) _, e := spentInMempool[txid+strconv.Itoa(int(utxo.Vout))] if !e { + // Get ScriptPubKey for vout and check if it is a cold staking contract + bchainTx, _, _ := w.txCache.GetTransaction(txid) + script, _ := hex.DecodeString(bchainTx.Vout[utxo.Vout].ScriptPubKey.Hex) + stakeContract := pivx.IsP2CSScript(script) + r = append(r, Utxo{ Txid: txid, Vout: utxo.Vout,