Skip to content

Commit 78baa5e

Browse files
authored
docs(examples): add P2PKH validation example (#38)
1 parent 4918f74 commit 78baa5e

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

examples/example.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
11
// Package examples provides example code for various functionalities.
22
package examples
33

4-
// TODO - add example code here
4+
import (
5+
"fmt"
6+
"os"
7+
8+
chaincfg "github.com/bsv-blockchain/go-chaincfg"
9+
"github.com/bsv-blockchain/go-wire"
10+
)
11+
12+
// ExampleIsPubKeyHashAddrID demonstrates how to verify the legacy public key hash
13+
// (P2PKH) address identifier bytes for a specific Bitcoin SV network.
14+
//
15+
// The helper reports whether the provided identifier is valid for the supplied
16+
// network magic value. This is useful when parsing external configuration or
17+
// performing sanity checks on user-supplied address metadata.
18+
func ExampleIsPubKeyHashAddrID() {
19+
write := func(value bool) {
20+
if _, err := fmt.Fprintf(os.Stdout, "%t\n", value); err != nil {
21+
panic(err)
22+
}
23+
}
24+
25+
write(chaincfg.IsPubKeyHashAddrID(wire.MainNet, chaincfg.MainNetParams.LegacyPubKeyHashAddrID))
26+
write(chaincfg.IsPubKeyHashAddrID(wire.MainNet, chaincfg.TestNetParams.LegacyPubKeyHashAddrID))
27+
28+
// Output:
29+
// true
30+
// false
31+
}

0 commit comments

Comments
 (0)