Skip to content

Commit

Permalink
Payment documentation (#49)
Browse files Browse the repository at this point in the history
* added factory method FromPublicKeys for creating multiscript payment

* payment documentation
  • Loading branch information
sekulicd authored May 21, 2020
1 parent 8abea0a commit 7f2f146
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions payment/doc.go
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
34 changes: 34 additions & 0 deletions payment/examples_test.go
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)
}

0 comments on commit 7f2f146

Please sign in to comment.