indexers: Convert to use stdscript.
This converts the blockchain/indexers package to use the stdscript package instead of txscript. This is part of a series of commits to convert all packages in the repository to make use of the new stdscript package.
This commit is contained in:
parent
175d680afc
commit
f0be987b2a
@ -16,8 +16,8 @@ import (
|
||||
"github.com/decred/dcrd/chaincfg/v3"
|
||||
"github.com/decred/dcrd/database/v3"
|
||||
"github.com/decred/dcrd/dcrutil/v4"
|
||||
"github.com/decred/dcrd/txscript/v4"
|
||||
"github.com/decred/dcrd/txscript/v4/stdaddr"
|
||||
"github.com/decred/dcrd/txscript/v4/stdscript"
|
||||
"github.com/decred/dcrd/wire"
|
||||
)
|
||||
|
||||
@ -748,14 +748,14 @@ type writeIndexData map[[addrKeySize]byte][]int
|
||||
func (idx *AddrIndex) indexPkScript(data writeIndexData, scriptVersion uint16, pkScript []byte, txIdx int, isSStx bool, isTreasuryEnabled bool) {
|
||||
// Nothing to index if the script is non-standard or otherwise doesn't
|
||||
// contain any addresses.
|
||||
class, addrs, _, err := txscript.ExtractPkScriptAddrs(scriptVersion,
|
||||
pkScript, idx.chainParams, isTreasuryEnabled)
|
||||
if err != nil {
|
||||
params := idx.chainParams
|
||||
scriptType, addrs := stdscript.ExtractAddrs(scriptVersion, pkScript, params)
|
||||
if scriptType == stdscript.STNonStandard {
|
||||
return
|
||||
}
|
||||
|
||||
if isSStx && class == txscript.NullDataTy {
|
||||
addr, err := stake.AddrFromSStxPkScrCommitment(pkScript, idx.chainParams)
|
||||
if isSStx && scriptType == stdscript.STNullData {
|
||||
addr, err := stake.AddrFromSStxPkScrCommitment(pkScript, params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -993,13 +993,10 @@ func (idx *AddrIndex) EntriesForAddress(dbTx database.Tx, addr stdaddr.Address,
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (idx *AddrIndex) indexUnconfirmedAddresses(scriptVersion uint16, pkScript []byte, tx *dcrutil.Tx, isSStx bool, isTreasuryEnabled bool) {
|
||||
// The error is ignored here since the only reason it can fail is if the
|
||||
// script fails to parse and it was already validated before being
|
||||
// admitted to the mempool.
|
||||
class, addrs, _, _ := txscript.ExtractPkScriptAddrs(scriptVersion, pkScript,
|
||||
idx.chainParams, isTreasuryEnabled)
|
||||
params := idx.chainParams
|
||||
scriptType, addrs := stdscript.ExtractAddrs(scriptVersion, pkScript, params)
|
||||
|
||||
if isSStx && class == txscript.NullDataTy {
|
||||
if isSStx && scriptType == stdscript.STNullData {
|
||||
addr, err := stake.AddrFromSStxPkScrCommitment(pkScript, idx.chainParams)
|
||||
if err != nil {
|
||||
// Fail if this fails to decode. It should.
|
||||
|
||||
@ -15,7 +15,7 @@ import (
|
||||
"github.com/decred/dcrd/blockchain/v4/chaingen"
|
||||
"github.com/decred/dcrd/chaincfg/v3"
|
||||
"github.com/decred/dcrd/database/v3"
|
||||
"github.com/decred/dcrd/txscript/v4"
|
||||
"github.com/decred/dcrd/txscript/v4/stdscript"
|
||||
"github.com/decred/dcrd/wire"
|
||||
)
|
||||
|
||||
@ -425,11 +425,8 @@ func TestAddrIndexAsync(t *testing.T) {
|
||||
|
||||
// Fetch the first address paid to by bk5's coinbase.
|
||||
out := bk5.MsgBlock().Transactions[0].TxOut[0]
|
||||
_, addrs, _, err := txscript.ExtractPkScriptAddrs(out.Version,
|
||||
out.PkScript, addrIdx.chainParams, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, addrs := stdscript.ExtractAddrs(out.Version, out.PkScript,
|
||||
addrIdx.chainParams)
|
||||
|
||||
// Ensure the address index has the first address paid to by bk5's
|
||||
// coinbase indexed.
|
||||
|
||||
@ -14,8 +14,8 @@ import (
|
||||
"github.com/decred/dcrd/chaincfg/v3"
|
||||
"github.com/decred/dcrd/database/v3"
|
||||
"github.com/decred/dcrd/dcrutil/v4"
|
||||
"github.com/decred/dcrd/txscript/v4"
|
||||
"github.com/decred/dcrd/txscript/v4/stdaddr"
|
||||
"github.com/decred/dcrd/txscript/v4/stdscript"
|
||||
"github.com/decred/dcrd/wire"
|
||||
)
|
||||
|
||||
@ -330,45 +330,37 @@ func (idx *ExistsAddrIndex) connectBlock(dbTx database.Tx, block, parent *dcruti
|
||||
isSStx := stake.IsSStx(msgTx)
|
||||
for _, txIn := range msgTx.TxIn {
|
||||
// Note that the functions used here require v0 scripts. Hence it
|
||||
// is used for the script version. This will ultimately need to
|
||||
// is used for the script version. This will ultimately need to be
|
||||
// updated to support new script versions.
|
||||
const scriptVersion = 0
|
||||
if txscript.IsMultisigSigScript(txIn.SignatureScript) {
|
||||
rs := txscript.MultisigRedeemScriptFromScriptSig(
|
||||
txIn.SignatureScript)
|
||||
class, addrs, _, err := txscript.ExtractPkScriptAddrs(
|
||||
scriptVersion, rs, idx.chain.ChainParams(),
|
||||
isTreasuryEnabled)
|
||||
if !stdscript.IsMultiSigSigScriptV0(txIn.SignatureScript) {
|
||||
continue
|
||||
}
|
||||
rs := stdscript.MultiSigRedeemScriptFromScriptSigV0(txIn.SignatureScript)
|
||||
typ, addrs := stdscript.ExtractAddrsV0(rs, idx.chain.ChainParams())
|
||||
if typ != stdscript.STMultiSig {
|
||||
// This should never happen, but be paranoid.
|
||||
continue
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
k, err := addrToKey(addr)
|
||||
if err != nil {
|
||||
// Non-standard outputs are skipped.
|
||||
continue
|
||||
}
|
||||
if class != txscript.MultiSigTy {
|
||||
// This should never happen, but be paranoid.
|
||||
continue
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
k, err := addrToKey(addr)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
usedAddrs[k] = struct{}{}
|
||||
}
|
||||
usedAddrs[k] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
for _, txOut := range tx.MsgTx().TxOut {
|
||||
class, addrs, _, err := txscript.ExtractPkScriptAddrs(
|
||||
txOut.Version, txOut.PkScript, idx.chain.ChainParams(),
|
||||
isTreasuryEnabled)
|
||||
if err != nil {
|
||||
scriptType, addrs := stdscript.ExtractAddrs(txOut.Version,
|
||||
txOut.PkScript, idx.chain.ChainParams())
|
||||
if scriptType == stdscript.STNonStandard {
|
||||
// Non-standard outputs are skipped.
|
||||
continue
|
||||
}
|
||||
|
||||
if isSStx && class == txscript.NullDataTy {
|
||||
if isSStx && scriptType == stdscript.STNullData {
|
||||
addr, err := stake.AddrFromSStxPkScrCommitment(txOut.PkScript,
|
||||
idx.chain.ChainParams())
|
||||
if err != nil {
|
||||
@ -453,47 +445,41 @@ func (idx *ExistsAddrIndex) disconnectBlock(dbTx database.Tx, block, parent *dcr
|
||||
func (idx *ExistsAddrIndex) addUnconfirmedTx(tx *wire.MsgTx, isTreasuryEnabled bool) {
|
||||
isSStx := stake.IsSStx(tx)
|
||||
for _, txIn := range tx.TxIn {
|
||||
if txscript.IsMultisigSigScript(txIn.SignatureScript) {
|
||||
// Note that the functions used here require v0 scripts. Hence it
|
||||
// is used for the script version. This will ultimately need to
|
||||
// updated to support new script versions.
|
||||
const scriptVersion = 0
|
||||
rs := txscript.MultisigRedeemScriptFromScriptSig(
|
||||
txIn.SignatureScript)
|
||||
class, addrs, _, err := txscript.ExtractPkScriptAddrs(
|
||||
scriptVersion, rs, idx.chain.ChainParams(),
|
||||
isTreasuryEnabled)
|
||||
// Note that the functions used here require v0 scripts. Hence it is
|
||||
// used for the script version. This will ultimately need to be updated
|
||||
// to support new script versions.
|
||||
if !stdscript.IsMultiSigSigScriptV0(txIn.SignatureScript) {
|
||||
continue
|
||||
}
|
||||
|
||||
rs := stdscript.MultiSigRedeemScriptFromScriptSigV0(txIn.SignatureScript)
|
||||
scriptType, addrs := stdscript.ExtractAddrsV0(rs, idx.chain.ChainParams())
|
||||
if scriptType != stdscript.STMultiSig {
|
||||
// This should never happen, but be paranoid.
|
||||
continue
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
k, err := addrToKey(addr)
|
||||
if err != nil {
|
||||
// Non-standard outputs are skipped.
|
||||
continue
|
||||
}
|
||||
if class != txscript.MultiSigTy {
|
||||
// This should never happen, but be paranoid.
|
||||
continue
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
k, err := addrToKey(addr)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, exists := idx.mpExistsAddr[k]; !exists {
|
||||
idx.mpExistsAddr[k] = struct{}{}
|
||||
}
|
||||
if _, exists := idx.mpExistsAddr[k]; !exists {
|
||||
idx.mpExistsAddr[k] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, txOut := range tx.TxOut {
|
||||
class, addrs, _, err := txscript.ExtractPkScriptAddrs(txOut.Version,
|
||||
txOut.PkScript, idx.chain.ChainParams(), isTreasuryEnabled)
|
||||
if err != nil {
|
||||
scriptType, addrs := stdscript.ExtractAddrs(txOut.Version,
|
||||
txOut.PkScript, idx.chain.ChainParams())
|
||||
if scriptType == stdscript.STNonStandard {
|
||||
// Non-standard outputs are skipped.
|
||||
continue
|
||||
}
|
||||
|
||||
if isSStx && class == txscript.NullDataTy {
|
||||
if isSStx && scriptType == stdscript.STNullData {
|
||||
addr, err := stake.AddrFromSStxPkScrCommitment(txOut.PkScript,
|
||||
idx.chain.ChainParams())
|
||||
if err != nil {
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/decred/dcrd/blockchain/v4/chaingen"
|
||||
"github.com/decred/dcrd/chaincfg/v3"
|
||||
"github.com/decred/dcrd/txscript/v4"
|
||||
"github.com/decred/dcrd/txscript/v4/stdscript"
|
||||
)
|
||||
|
||||
// TestExistsAddrIndexAsync ensures the exist address index
|
||||
@ -100,18 +100,10 @@ func TestExistsAddrIndexAsync(t *testing.T) {
|
||||
bk5.Hash().String(), tipHash.String())
|
||||
}
|
||||
|
||||
isTreasuryEnabled, err := idx.chain.IsTreasuryAgendaActive(bk5.Hash())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Fetch the first address paid to by bk5's coinbase.
|
||||
out := bk5.MsgBlock().Transactions[0].TxOut[0]
|
||||
_, addrs, _, err := txscript.ExtractPkScriptAddrs(out.Version, out.PkScript,
|
||||
idx.chain.ChainParams(), isTreasuryEnabled)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, addrs := stdscript.ExtractAddrs(out.Version, out.PkScript,
|
||||
idx.chain.ChainParams())
|
||||
|
||||
// Ensure index has the first address paid to by bk5's coinbase indexed.
|
||||
indexed, err := idx.ExistsAddress(addrs[0])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user