payment

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2020 License: MIT Imports: 9 Imported by: 13

Documentation

Overview

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.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Payment

type Payment struct {
	Network     *network.Network
	PublicKey   *btcec.PublicKey
	Hash        []byte
	BlindingKey *btcec.PublicKey
	Redeem      *Payment
	Script      []byte
	WitnessHash []byte
}

Payment defines the structure that holds the information different addresses

func FromPayment

func FromPayment(payment *Payment) (*Payment, error)

FromPayment creates a Payment struct from a another Payment

Example

This examples shows how nested payment can be done in order to create non native SegWit(P2SH-P2WPKH) address

package main

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)

func main() {
	_, 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)
}

func FromPublicKey

func FromPublicKey(pubkey *btcec.PublicKey, net *network.Network) *Payment

FromPublicKey creates a Payment struct from a btcec.publicKey

Example

This examples shows how standard P2PKH address can be created

package main

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)

func main() {
	_, publicKey := btcec.PrivKeyFromBytes(btcec.S256(), privateKeyBytes)
	pay := payment.FromPublicKey(publicKey, &network.Regtest)
	fmt.Printf("P2PKH address %v\n:", pay.PubKeyHash())
}

func FromPublicKeys

func FromPublicKeys(pubkeys []*btcec.PublicKey, nrequired int, net *network.Network) (*Payment, error)

FromPublicKeys creates a multi-signature Payment struct from list of public key's

func FromScript

func FromScript(script []byte, net *network.Network) (*Payment, error)

FromPayment creates a nested Payment struct from script

func (*Payment) PubKeyHash

func (p *Payment) PubKeyHash() string

PubKeyHash is a method of the Payment struct to derive a base58 p2pkh address

func (*Payment) ScriptHash

func (p *Payment) ScriptHash() (string, error)

ScriptHash is a method of the Payment struct to derive a base58 p2sh address

func (*Payment) WitnessPubKeyHash

func (p *Payment) WitnessPubKeyHash() (string, error)

WitnessPubKeyHash is a method of the Payment struct to derive a base58 p2wpkh address

func (*Payment) WitnessScriptHash

func (p *Payment) WitnessScriptHash() (string, error)

WitnessScriptHash is a method of the Payment struct to derive a base58 p2wsh address

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL