change to btc.TryParseOPReturn
This commit is contained in:
parent
207a6b36e8
commit
43e61253ee
@ -3,7 +3,6 @@ package monacoin
|
|||||||
import (
|
import (
|
||||||
"blockbook/bchain"
|
"blockbook/bchain"
|
||||||
"blockbook/bchain/coins/btc"
|
"blockbook/bchain/coins/btc"
|
||||||
"encoding/hex"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/jakm/btcutil/chaincfg"
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
@ -137,7 +136,7 @@ func (p *MonacoinParser) outputScriptToAddresses(script []byte) ([]string, bool,
|
|||||||
if sc != txscript.NonStandardTy && sc != txscript.NullDataTy {
|
if sc != txscript.NonStandardTy && sc != txscript.NullDataTy {
|
||||||
s = true
|
s = true
|
||||||
} else if len(rv) == 0 {
|
} else if len(rv) == 0 {
|
||||||
or := TryParseOPReturn(script)
|
or := btc.TryParseOPReturn(script)
|
||||||
if or != "" {
|
if or != "" {
|
||||||
rv = []string{or}
|
rv = []string{or}
|
||||||
}
|
}
|
||||||
@ -156,7 +155,7 @@ func (p *MonacoinParser) outputScriptToAddresses(script []byte) ([]string, bool,
|
|||||||
if sc != txscript.NonStandardTy && sc != txscript.NullDataTy {
|
if sc != txscript.NonStandardTy && sc != txscript.NullDataTy {
|
||||||
s = true
|
s = true
|
||||||
} else if len(rv) == 0 {
|
} else if len(rv) == 0 {
|
||||||
or := TryParseOPReturn(script)
|
or := btc.TryParseOPReturn(script)
|
||||||
if or != "" {
|
if or != "" {
|
||||||
rv = []string{or}
|
rv = []string{or}
|
||||||
}
|
}
|
||||||
@ -164,43 +163,3 @@ func (p *MonacoinParser) outputScriptToAddresses(script []byte) ([]string, bool,
|
|||||||
return rv, s, nil
|
return rv, s, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TryParseOPReturn tries to process OP_RETURN script and return its string representation
|
|
||||||
func TryParseOPReturn(script []byte) string {
|
|
||||||
if len(script) > 1 && script[0] == txscript.OP_RETURN {
|
|
||||||
// trying 2 variants of OP_RETURN data
|
|
||||||
// 1) OP_RETURN OP_PUSHDATA1 <datalen> <data>
|
|
||||||
// 2) OP_RETURN <datalen> <data>
|
|
||||||
var data []byte
|
|
||||||
var l int
|
|
||||||
if script[1] == txscript.OP_PUSHDATA1 && len(script) > 2 {
|
|
||||||
l = int(script[2])
|
|
||||||
data = script[3:]
|
|
||||||
if l != len(data) {
|
|
||||||
l = int(script[1])
|
|
||||||
data = script[2:]
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
l = int(script[1])
|
|
||||||
data = script[2:]
|
|
||||||
}
|
|
||||||
if l == len(data) {
|
|
||||||
isASCII := true
|
|
||||||
for _, c := range data {
|
|
||||||
if c < 32 || c > 127 {
|
|
||||||
isASCII = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var ed string
|
|
||||||
if isASCII {
|
|
||||||
ed = "(" + string(data) + ")"
|
|
||||||
} else {
|
|
||||||
ed = hex.EncodeToString(data)
|
|
||||||
}
|
|
||||||
return "OP_RETURN " + ed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user