|
1 |
| -// Package address provides utilities for working with Bitcoin address types. |
2 |
| -// |
3 |
| -// Bitcoin uses different address types, such as Pay-to-Public-Key-Hash (P2PKH), |
4 |
| -// Pay-to-Script-Hash (P2SH), and Segregated Witness (SegWit) addresses. This package |
5 |
| -// offers functions for creating, parsing, and validating addresses of these types. |
6 |
| -// |
7 |
| -// Usage: |
8 |
| -// - Use the functions in this package to generate Bitcoin addresses. |
9 |
| -// - Parse Bitcoin addresses to extract information. |
10 |
| -// - Validate Bitcoin addresses to ensure they adhere to the correct format. |
11 |
| -// - Create address from scripts p2wsh, p2tr, tapleaf, .... |
12 |
| -// |
13 |
| -// Example: |
14 |
| -// package main |
15 |
| -// |
16 |
| -// import ( |
17 |
| -// "fmt" |
18 |
| -// "github.com/mrtnetwork/bitcoin/address" |
19 |
| -// ) |
20 |
| -// |
21 |
| -// func main() { |
22 |
| -// P2PKH ADDRESS |
23 |
| -// address in testnet: myVMJgRi6arv4hLbeUcJYKUJWmFnpjtVme |
24 |
| -// address in mainnet: 1JyQ1dLjHZRfHaryvudviQFyemf5vjbmUf |
25 |
| -// exampleAddr1, _ := address.P2PKHAddressFromAddress("myVMJgRi6arv4hLbeUcJYKUJWmFnpjtVme") |
26 |
| -// fmt.Println("address in testnet: ", exampleAddr1.Show(address.TestnetNetwork)) |
27 |
| -// fmt.Println("address in mainnet: ", exampleAddr1.Show(address.MainnetNetwork)) |
28 |
| - |
29 |
| -// P2TR ADDRESS |
30 |
| -// address in testnet: tb1pyhmqwlcrws4dxcgalt4mrffgnys879vs59xf6sve4hazyvmhecxq3e6sc0 |
31 |
| -// address in mainnet: bc1pyhmqwlcrws4dxcgalt4mrffgnys879vs59xf6sve4hazyvmhecxqx3vlzq |
32 |
| -// exampleAddr2, _ := address.P2TRAddressFromAddress("tb1pyhmqwlcrws4dxcgalt4mrffgnys879vs59xf6sve4hazyvmhecxq3e6sc0") |
33 |
| -// fmt.Println("address in testnet: ", exampleAddr2.Show(address.TestnetNetwork)) |
34 |
| -// fmt.Println("address in mainnet: ", exampleAddr2.Show(address.MainnetNetwork)) |
35 |
| - |
36 |
| -// P2SH(P2PKH) ADDRESS |
37 |
| -// address in testnet: 2N2yqygBJRvDzLzvPe91qKfSYnK5utGckJX |
38 |
| -// address in mainnet: 3BRduwFGpTie9DHqy1PxhiTHZxsk7jpr9x |
39 |
| -// exampleAddr3, _ := address.P2SHAddressFromAddress("2N2yqygBJRvDzLzvPe91qKfSYnK5utGckJX", address.P2PKHInP2SH) |
40 |
| -// fmt.Println("address in testnet: ", exampleAddr3.Show(address.TestnetNetwork)) |
41 |
| -// fmt.Println("address in mainnet: ", exampleAddr3.Show(address.MainnetNetwork)) |
42 |
| - |
43 |
| -// P2PKH ADDRESS |
44 |
| -// address in testnet: mzUzciYUGsNxLCaaHwou27F4RbnDTzKomV |
45 |
| -// address in mainnet: 1Ky3KfTVTqwhZ66xaNqXCC2jZcBWZD6ppQ |
46 |
| -// exampleAddr4, _ := address.P2PKHAddressFromAddress("mzUzciYUGsNxLCaaHwou27F4RbnDTzKomV") |
47 |
| -// fmt.Println("address in testnet: ", exampleAddr4.Show(address.TestnetNetwork)) |
48 |
| -// fmt.Println("address in mainnet: ", exampleAddr4.Show(address.MainnetNetwork)) |
49 |
| - |
50 |
| -// P2SH(P2PKH) ADDRESS |
51 |
| -// address in testnet: 2MzibgEeJYCN8mjJsZTg79AH7au4PCkHXHo |
52 |
| -// address in mainnet: 39APcViGvjrnZwgKtL4EXDHrNYrDT9YuCQ |
53 |
| -// exampleAddr5, _ := address.P2SHAddressFromAddress("2MzibgEeJYCN8mjJsZTg79AH7au4PCkHXHo", address.P2PKHInP2SH) |
54 |
| -// fmt.Println("address in testnet: ", exampleAddr5.Show(address.TestnetNetwork)) |
55 |
| -// fmt.Println("address in mainnet: ", exampleAddr5.Show(address.MainnetNetwork)) |
56 |
| - |
57 |
| -// P2SH(P2WSH) ADDRESS |
58 |
| -// address in testnet: 2N7bNV1WPwCVHfoqqRhvtmbAfktazfjHEW2 |
59 |
| -// address in mainnet: 3G3ARGaNKjywU2DHkaK29eBQYYNppD2xDE |
60 |
| -// exampleAddr6, _ := address.P2SHAddressFromAddress("2N7bNV1WPwCVHfoqqRhvtmbAfktazfjHEW2", address.P2WSHInP2SH) |
61 |
| -// fmt.Println("address in testnet: ", exampleAddr6.Show(address.TestnetNetwork)) |
62 |
| -// fmt.Println("address in mainnet: ", exampleAddr6.Show(address.MainnetNetwork)) |
63 |
| - |
64 |
| -// P2SH(P2WPKH) ADDRESS |
65 |
| -// address in testnet: 2N38S8G9q6qyEjPWmicqxrVwjq4QiTbcyf4 |
66 |
| -// address in mainnet: 3BaE4XDoVPTtXbtE3VE6EYxUciCYd5rspb |
67 |
| -// exampleAddr7, _ := address.P2SHAddressFromAddress("2N38S8G9q6qyEjPWmicqxrVwjq4QiTbcyf4", address.P2WPKHInP2SH) |
68 |
| -// fmt.Println("address in testnet: ", exampleAddr7.Show(address.TestnetNetwork)) |
69 |
| -// fmt.Println("address in mainnet: ", exampleAddr7.Show(address.MainnetNetwork)) |
70 |
| - |
71 |
| -// P2SH(P2PK) ADDRESS |
72 |
| -// address in testnet: 2MugsNcgzLJ1HosnZyC2CfZVmgbMPK1XubR |
73 |
| -// address in mainnet: 348fJskxiqVwc6A2J4QL3cWWUF9DbWjTni |
74 |
| -// exampleAddr8, _ := address.P2SHAddressFromAddress("2MugsNcgzLJ1HosnZyC2CfZVmgbMPK1XubR", address.P2PKInP2SH) |
75 |
| -// fmt.Println("address in testnet: ", exampleAddr8.Show(address.TestnetNetwork)) |
76 |
| -// fmt.Println("address in mainnet: ", exampleAddr8.Show(address.MainnetNetwork)) |
77 |
| - |
78 |
| -// P2WPKH ADDRESS |
79 |
| -// address in testnet: tb1q6q9halaazasd42gzsc2cvv5xls295w7kawkhxy |
80 |
| -// address in mainnet: bc1q6q9halaazasd42gzsc2cvv5xls295w7khgdyah |
81 |
| -// exampleAddr9, _ := address.P2WPKHAddresssFromAddress("tb1q6q9halaazasd42gzsc2cvv5xls295w7kawkhxy") |
82 |
| -// fmt.Println("address in testnet: ", exampleAddr9.Show(address.TestnetNetwork)) |
83 |
| -// fmt.Println("address in mainnet: ", exampleAddr9.Show(address.MainnetNetwork)) |
84 |
| -// } |
85 |
| -// |
86 |
| -// This package aims to simplify Bitcoin address handling and make it easier to work |
87 |
| -// with different Bitcoin address formats. |
88 |
| - |
| 1 | +// Implementation of various Bitcoin address types, including P2PKH, P2SH, and SegWit |
89 | 2 | package address
|
90 | 3 |
|
91 | 4 | import "github.com/mrtnetwork/bitcoin/scripts"
|
|
0 commit comments