[lbry] remove claim prefix for addr calculation

This commit is contained in:
Brannon King 2021-07-23 12:13:31 -04:00 committed by Roy Lee
parent 5f872b37cf
commit a06875fe46
3 changed files with 41 additions and 8 deletions

View file

@ -701,11 +701,12 @@ func createVoutList(mtx *wire.MsgTx, chainParams *chaincfg.Params, filterAddrMap
// script doesn't fully parse, so ignore the error here. // script doesn't fully parse, so ignore the error here.
disbuf, _ := txscript.DisasmString(v.PkScript) disbuf, _ := txscript.DisasmString(v.PkScript)
script := txscript.StripClaimScriptPrefix(v.PkScript)
// Ignore the error here since an error means the script // Ignore the error here since an error means the script
// couldn't parse and there is no additional information about // couldn't parse and there is no additional information about
// it anyways. // it anyways.
scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs( scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(script, chainParams)
v.PkScript, chainParams)
// Encode the addresses while checking if the address passes the // Encode the addresses while checking if the address passes the
// filter when needed. // filter when needed.
@ -735,9 +736,19 @@ func createVoutList(mtx *wire.MsgTx, chainParams *chaincfg.Params, filterAddrMap
vout.ScriptPubKey.Addresses = encodedAddrs vout.ScriptPubKey.Addresses = encodedAddrs
vout.ScriptPubKey.Asm = disbuf vout.ScriptPubKey.Asm = disbuf
vout.ScriptPubKey.Hex = hex.EncodeToString(v.PkScript) vout.ScriptPubKey.Hex = hex.EncodeToString(v.PkScript)
vout.ScriptPubKey.Type = scriptClass.String()
vout.ScriptPubKey.ReqSigs = int32(reqSigs) vout.ScriptPubKey.ReqSigs = int32(reqSigs)
if len(script) < len(v.PkScript) {
vout.ScriptPubKey.IsClaim = v.PkScript[0] == txscript.OP_CLAIMNAME || v.PkScript[0] == txscript.OP_UPDATECLAIM
vout.ScriptPubKey.IsSupport = v.PkScript[0] == txscript.OP_SUPPORTCLAIM
vout.ScriptPubKey.SubType = scriptClass.String()
vout.ScriptPubKey.Type = txscript.ScriptClass.String(0)
} else {
vout.ScriptPubKey.Type = scriptClass.String()
}
// TODO here: isclaim, issupport, subtype,
voutList = append(voutList, vout) voutList = append(voutList, vout)
} }
@ -2780,10 +2791,12 @@ func handleGetTxOut(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
// doesn't fully parse, so ignore the error here. // doesn't fully parse, so ignore the error here.
disbuf, _ := txscript.DisasmString(pkScript) disbuf, _ := txscript.DisasmString(pkScript)
script := txscript.StripClaimScriptPrefix(pkScript)
// Get further info about the script. // Get further info about the script.
// Ignore the error here since an error means the script couldn't parse // Ignore the error here since an error means the script couldn't parse
// and there is no additional information about it anyways. // and there is no additional information about it anyways.
scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(pkScript, scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(script,
s.cfg.ChainParams) s.cfg.ChainParams)
addresses := make([]string, len(addrs)) addresses := make([]string, len(addrs))
for i, addr := range addrs { for i, addr := range addrs {
@ -2798,11 +2811,20 @@ func handleGetTxOut(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
Asm: disbuf, Asm: disbuf,
Hex: hex.EncodeToString(pkScript), Hex: hex.EncodeToString(pkScript),
ReqSigs: int32(reqSigs), ReqSigs: int32(reqSigs),
Type: scriptClass.String(),
Addresses: addresses, Addresses: addresses,
}, },
Coinbase: isCoinbase, Coinbase: isCoinbase,
} }
if len(script) < len(pkScript) {
txOutReply.ScriptPubKey.IsClaim = pkScript[0] == txscript.OP_CLAIMNAME || pkScript[0] == txscript.OP_UPDATECLAIM
txOutReply.ScriptPubKey.IsSupport = pkScript[0] == txscript.OP_SUPPORTCLAIM
txOutReply.ScriptPubKey.SubType = scriptClass.String()
txOutReply.ScriptPubKey.Type = txscript.ScriptClass.String(0)
} else {
txOutReply.ScriptPubKey.Type = scriptClass.String()
}
return txOutReply, nil return txOutReply, nil
} }
@ -3014,7 +3036,7 @@ func createVinListPrevOut(s *rpcServer, mtx *wire.MsgTx, chainParams *chaincfg.P
// Ignore the error here since an error means the script // Ignore the error here since an error means the script
// couldn't parse and there is no additional information about // couldn't parse and there is no additional information about
// it anyways. // it anyways.
_, addrs, _, _ := txscript.ExtractPkScriptAddrs( class, addrs, _, _ := txscript.ExtractPkScriptAddrs(
originTxOut.PkScript, chainParams) originTxOut.PkScript, chainParams)
// Encode the addresses while checking if the address passes the // Encode the addresses while checking if the address passes the
@ -3051,6 +3073,9 @@ func createVinListPrevOut(s *rpcServer, mtx *wire.MsgTx, chainParams *chaincfg.P
vinListEntry.PrevOut = &btcjson.PrevOut{ vinListEntry.PrevOut = &btcjson.PrevOut{
Addresses: encodedAddrs, Addresses: encodedAddrs,
Value: btcutil.Amount(originTxOut.Value).ToBTC(), Value: btcutil.Amount(originTxOut.Value).ToBTC(),
IsClaim: class == txscript.NonStandardTy &&
(originTxOut.PkScript[0] == txscript.OP_CLAIMNAME || originTxOut.PkScript[0] == txscript.OP_UPDATECLAIM),
IsSupport: class == txscript.NonStandardTy && originTxOut.PkScript[0] == txscript.OP_SUPPORTCLAIM,
} }
} }
} }

View file

@ -157,7 +157,9 @@ func sign(chainParams *chaincfg.Params, tx *wire.MsgTx, idx int,
subScript []byte, hashType SigHashType, kdb KeyDB, sdb ScriptDB) ([]byte, subScript []byte, hashType SigHashType, kdb KeyDB, sdb ScriptDB) ([]byte,
ScriptClass, []btcutil.Address, int, error) { ScriptClass, []btcutil.Address, int, error) {
class, addresses, nrequired, err := ExtractPkScriptAddrs(subScript, subSubScript := StripClaimScriptPrefix(subScript)
class, addresses, nrequired, err := ExtractPkScriptAddrs(subSubScript,
chainParams) chainParams)
if err != nil { if err != nil {
return nil, NonStandardTy, nil, 0, err return nil, NonStandardTy, nil, 0, err

View file

@ -543,9 +543,11 @@ func ExtractPkScriptAddrs(pkScript []byte, chainParams *chaincfg.Params) (Script
var addrs []btcutil.Address var addrs []btcutil.Address
var requiredSigs int var requiredSigs int
stripped := StripClaimScriptPrefix(pkScript)
// No valid addresses or required signatures if the script doesn't // No valid addresses or required signatures if the script doesn't
// parse. // parse.
pops, err := parseScript(pkScript) pops, err := parseScript(stripped)
if err != nil { if err != nil {
return NonStandardTy, nil, 0, err return NonStandardTy, nil, 0, err
} }
@ -639,6 +641,10 @@ func ExtractPkScriptAddrs(pkScript []byte, chainParams *chaincfg.Params) (Script
// nonstandard transactions. // nonstandard transactions.
} }
if len(stripped) < len(pkScript) {
scriptClass = NonStandardTy
}
return scriptClass, addrs, requiredSigs, nil return scriptClass, addrs, requiredSigs, nil
} }