Skip to content

Commit

Permalink
Merge pull request #14 from PeterL73/checkcoldstakeverify
Browse files Browse the repository at this point in the history
add OP_CHECKCOLDSTAKEVERIFY_LOF
  • Loading branch information
DeanSparrow committed Nov 27, 2022
2 parents a584cdd + 70b81a8 commit 90af96e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
12 changes: 10 additions & 2 deletions api/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"blockbook/db"
"bytes"
"encoding/json"
"encoding/hex"
"fmt"
"math"
"math/big"
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions bchain/coins/pivx/pivxparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 &&
Expand Down
5 changes: 3 additions & 2 deletions db/rocksdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 90af96e

Please sign in to comment.