chaincfgs

package module
v0.0.0-...-abb8cce Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2019 License: BSD-3-Clause Imports: 3 Imported by: 0

README

chaincfgs

godoc

work-in-progress. please do not use in production

Documentation

Overview

Package chaincfgs is a collection of chaincfgs for bitcoin and altcoins

With this package, you can interact with multiple chains in one application

..such as signing transactions, creating addresses, and using addresses.

Adding a new altcoin

all coins must have at least COINMainnet, and optional alternate networks. Testnets can be named anything but must start with capital letter. Examples: BTCMainnet, BTCSimnet, ALTMainnet, COINMainnet, COINTestnet10

That is the extent of this package, and anything else is entirely out of scope.

To add a coin, edit this 'chains.go' file, using a similar coin as template.

Index

Examples

Constants

This section is empty.

Variables

these coins have implemented their own chaincfg package. so, let's use them if we can. otherwise, create custom Params

View Source
var AllCoins []btcchaincfg.Params
View Source
var ErrNotImplemented = fmt.Errorf("not implemented")
View Source
var (
	FAKEMainnet = Basic(Alt{"FAKE", 0x12141c17, "fake", 0x24, 0x26, 0x80, 0x06, 0x0A, [4]byte{0x04, 0x88, 0xad, 0xe4}, [4]byte{0x04, 0x88, 0xb2, 0x1e}, 0})
)

if the altcoin doesn't have a chaincfg package, we can make a basic one containing only relevant fields

Functions

func Basic

func Basic(alt Alt) btcchaincfg.Params

Basic returns a *btcchaincfg.Params from the given Alt fields

func Coin

func Coin(n string) (btcchaincfg.Params, error)
Example
package main

import (
	"fmt"
	"log"

	"github.com/aquachain/chaincfgs"
	"github.com/aquachain/hdwallet"
)

func main() {
	coincfg, err := chaincfgs.Coin("NMC")
	if err != nil {
		log.Fatalln(err)
	}
	wallet, err := hdwallet.NewFromMnemonic("tag volcano eight thank tide danger coast health above argue embrace heavy", "")
	if err != nil {
		log.Fatalln(err)
	}

	// bitcoin-style address
	addr, err := wallet.MasterKey().Address(&coincfg)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println(addr)
}
Output:

NDoRQT8LhDxVWGhB62zXbfX9Z3FNic1RMP

Types

type Alt

type Alt struct {
	Name string
	Net  uint32 // wire.BitcoinNet
	// Human-readable part for Bech32 encoded segwit addresses, as defined
	// in BIP 173.
	Bech32HRPSegwit string

	// Address encoding magics
	PubKeyHashAddrID        byte // First byte of a P2PKH address
	ScriptHashAddrID        byte // First byte of a P2SH address
	PrivateKeyID            byte // First byte of a WIF private key
	WitnessPubKeyHashAddrID byte // First byte of a P2WPKH address
	WitnessScriptHashAddrID byte // First byte of a P2WSH address

	// BIP32 hierarchical deterministic extended key magics
	HDPrivateKeyID [4]byte
	HDPublicKeyID  [4]byte

	// BIP44 coin type used in the hierarchical deterministic path for
	// address generation.
	HDCoinType uint32
}

Alt type is the minimal fields needed for what we need

func GetAlt

func GetAlt(n string) Alt

type Params

type Params = btcchaincfg.Params

Jump to

Keyboard shortcuts

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