-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added factory method FromPublicKeys for creating multiscript payment * payment documentation
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
Package payment is an abstract for working with all kind of addresses in Liquid network. | ||
It can be used for the creation of p2pkh, p2ms, p2sh, non-native SegWit and native SegWit addresses. | ||
It also provides support for confidential payments. | ||
*/ | ||
package payment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package payment_test | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"github.com/btcsuite/btcd/btcec" | ||
"github.com/vulpemventures/go-elements/network" | ||
"github.com/vulpemventures/go-elements/payment" | ||
) | ||
|
||
const ( | ||
privateKeyHex = "1cc080a4cd371eafcad489a29664af6a7276b362fe783443ce036552482b971d" | ||
) | ||
|
||
var privateKeyBytes, _ = hex.DecodeString(privateKeyHex) | ||
|
||
//This examples shows how standard P2PKH address can be created | ||
func ExampleFromPublicKey() { | ||
_, publicKey := btcec.PrivKeyFromBytes(btcec.S256(), privateKeyBytes) | ||
pay := payment.FromPublicKey(publicKey, &network.Regtest) | ||
fmt.Printf("P2PKH address %v\n:", pay.PubKeyHash()) | ||
} | ||
|
||
//This examples shows how nested payment can be done in order to create non native SegWit(P2SH-P2WPKH) address | ||
func ExampleFromPayment() { | ||
_, publicKey := btcec.PrivKeyFromBytes(btcec.S256(), privateKeyBytes) | ||
p2wpkh := payment.FromPublicKey(publicKey, &network.Regtest) | ||
pay, err := payment.FromPayment(p2wpkh) | ||
p2sh, err := pay.ScriptHash() | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
fmt.Printf("Non native SegWit address %v\n:", p2sh) | ||
} |