MCPcopy Index your code
hub / github.com/btcsuite/btcd / ExampleScriptTemplate

Function ExampleScriptTemplate

txscript/template.go:207–235  ·  view source on GitHub ↗

Example usage:

()

Source from the content-addressed store, hash-verified

205
206// Example usage:
207func ExampleScriptTemplate() {
208 localPubkey, _ := hex.DecodeString("14e8948c7afa71b6e6fad621256474b5959e0305")
209
210 scriptBytes, err := ScriptTemplate(`
211 OP_DUP OP_HASH160 0x14e8948c7afa71b6e6fad621256474b5959e0305 OP_EQUALVERIFY OP_CHECKSIG
212 OP_DUP OP_HASH160 {{ hex .LocalPubkeyHash }} OP_EQUALVERIFY OP_CHECKSIG
213 {{ .Timeout }} OP_CHECKLOCKTIMEVERIFY OP_DROP
214
215 {{- range $i := range_iter 0 3 }}
216 {{ add 10 $i }} OP_ADD
217 {{- end }}`,
218 WithScriptTemplateParams(map[string]interface{}{
219 "LocalPubkeyHash": localPubkey,
220 "Timeout": 1,
221 }),
222 )
223 if err != nil {
224 fmt.Printf("Error: %v\n", err)
225 return
226 }
227
228 asmScript, err := DisasmString(scriptBytes)
229 if err != nil {
230 fmt.Printf("Error converting to ASM: %v\n", err)
231 return
232 }
233
234 fmt.Printf("Script ASM:\n%s\n", asmScript)
235}

Callers

nothing calls this directly

Calls 3

ScriptTemplateFunction · 0.85
WithScriptTemplateParamsFunction · 0.85
DisasmStringFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…