MCPcopy Create free account
hub / github.com/copernet/copernicus / ScriptToAsmStr

Function ScriptToAsmStr

rpc/rawtransaction.go:157–212  ·  view source on GitHub ↗
(s *script.Script, attemptSighashDecode bool)

Source from the content-addressed store, hash-verified

155}
156
157func ScriptToAsmStr(s *script.Script, attemptSighashDecode bool) string {
158 var str string
159 for _, scriptOpcodes := range s.ParsedOpCodes {
160 if len(str) > 0 {
161 str += " "
162 }
163 opcode := scriptOpcodes.OpValue
164 vch := make([]byte, len(scriptOpcodes.Data))
165 copy(vch, scriptOpcodes.Data)
166
167 if opcode >= 0 && opcode <= opcodes.OP_PUSHDATA4 {
168 if len(vch) <= 4 {
169 num, _ := script.GetScriptNum(vch, false, script.DefaultMaxNumSize)
170 str += fmt.Sprintf("%d", num.Value)
171 } else {
172 // the IsUnspendable check makes sure not to try to decode
173 // OP_RETURN data that may match the format of a signature
174 if attemptSighashDecode && !s.IsUnspendable() {
175 var strSigHashDecode string
176 // goal: only attempt to decode a defined sighash type from
177 // data that looks like a signature within a scriptSig. This
178 // won't decode correctly formatted public keys in Pubkey or
179 // Multisig scripts due to the restrictions on the pubkey
180 // formats (see IsCompressedOrUncompressedPubKey) being
181 // incongruous with the checks in CheckSignatureEncoding.
182 flags := script.ScriptVerifyStrictEnc
183 if vch[len(vch)-1]&crypto.SigHashForkID != 0 {
184 // If the transaction is using SIGHASH_FORKID, we need
185 // to set the appropriate flag.
186 // TODO: Remove after the Hard Fork.
187 flags |= script.ScriptEnableSigHashForkID
188 }
189 err := script.CheckTransactionSignatureEncoding(vch, uint32(flags))
190 if err == nil {
191 sigHashType := int(vch[len(vch)-1])
192 for desc, hashType := range mapSigHashValues {
193 if hashType == sigHashType {
194 strSigHashDecode = "[" + desc + "]"
195 // remove the sighash type byte. it will be replaced
196 // by the decode.
197 vch = vch[:len(vch)-1]
198 break
199 }
200 }
201 }
202 str += hex.EncodeToString(vch) + strSigHashDecode
203 } else {
204 str += hex.EncodeToString(vch)
205 }
206 }
207 } else {
208 str += opcodes.GetOpName(int(opcode))
209 }
210 }
211 return str
212}
213
214func ScriptPubKeyToJSON(script *script.Script, includeHex bool) *btcjson.ScriptPubKeyResult {

Callers 3

getVinListFunction · 0.85
ScriptPubKeyToJSONFunction · 0.85
getCoinsFunction · 0.85

Calls 1

IsUnspendableMethod · 0.80

Tested by

no test coverage detected