Add ExtractPkScriptAddrs examples.

This commit is contained in:
Dave Collins 2014-07-08 14:59:57 -05:00
parent 631c7850ec
commit 95167204d9
2 changed files with 33 additions and 0 deletions

View File

@ -50,6 +50,10 @@ $ go get github.com/conformal/btcscript
prints the created script hex and uses the DisasmString function to display
the disassembled script.
* [Extracting Details from Standard Scripts]
(http://godoc.org/github.com/conformal/btcscript#example-ExtractPkScriptAddrs)
Demonstrates extracting information from a standard public key script.
## TODO
- Increase test coverage to 100%

View File

@ -5,6 +5,7 @@
package btcscript_test
import (
"encoding/hex"
"fmt"
"github.com/conformal/btcnet"
@ -46,3 +47,31 @@ func ExamplePayToAddrScript() {
// Script Hex: 76a914128004ff2fcaf13b2b91eb654b1dc2b674f7ec6188ac
// Script Disassembly: OP_DUP OP_HASH160 128004ff2fcaf13b2b91eb654b1dc2b674f7ec61 OP_EQUALVERIFY OP_CHECKSIG
}
// This example demonstrates extracting information from a standard public key
// script.
func ExampleExtractPkScriptAddrs() {
// Start with a standard pay-to-pubkey-hash script.
scriptHex := "76a914128004ff2fcaf13b2b91eb654b1dc2b674f7ec6188ac"
script, err := hex.DecodeString(scriptHex)
if err != nil {
fmt.Println(err)
return
}
// Extract and print details from the script.
scriptClass, addresses, reqSigs, err := btcscript.ExtractPkScriptAddrs(
script, &btcnet.MainNetParams)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Script Class:", scriptClass)
fmt.Println("Addresses:", addresses)
fmt.Println("Required Signatures:", reqSigs)
// Output:
// Script Class: pubkeyhash
// Addresses: [12gpXQVcCL2qhTNQgyLVdCFG2Qs2px98nV]
// Required Signatures: 1
}