wallet

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: ISC Imports: 16 Imported by: 0

README

Bitmark Wallet

This a implementation of Hierarchical Deterministic wallet according to BIP32. It currently supports bitcoin and litecoin.

Prerequisite

  • go 1.8+

Examples

seed := "fded5e8970380eef15f742348d28511111366ae6a55188402b16c69922006fe6"
walletData := "wallet.dat"
w := wallet.New(seed, walletData)
coinAccount, err = w.CoinAccount(wallet.BTC, wallet.Test(test), 0)
if err != nil {
    log.Fatal(err)
}
addr, err := coinAccount.NewExternalAddr()
fmt.Println(err)

Documentation

Overview

Example (NewWallet)
seedHex := "fded5e8970380eef15f742348d28511111366ae6a55188402b16c69922006fe6"
seed, err := hex.DecodeString(seedHex)
if err != nil {
	log.Fatal(err)
}
walletData := "wallet.dat"
w := wallet.New(seed, walletData)
coinAccount, err := w.CoinAccount(wallet.BTC, wallet.Test(true), 0)
if err != nil {
	log.Fatal(err)
}
address, err := coinAccount.NewExternalAddr()
if err != nil {
	log.Fatal(err)
}
fmt.Println(address)
Output:

mjWfeKTxhPD2eA9FbVrqTkGtZD19fHEgaU

Index

Examples

Constants

View Source
const (
	AddressGap = 5
)

Follow the rule of account discovery in BIP44 https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#account-discovery

Variables

View Source
var (
	//BitcoinMain is params for main net.
	BitcoinMain = &address.Params{
		DumpedPrivateKeyHeader: []byte{128},
		AddressHeader:          0,
		P2SHHeader:             5,
		HDPrivateKeyID:         []byte{0x04, 0x88, 0xad, 0xe4},
		HDPublicKeyID:          []byte{0x04, 0x88, 0xb2, 0x1e},
	}
	//BitcoinTest is params for test net.
	BitcoinTest = &address.Params{
		DumpedPrivateKeyHeader: []byte{239},
		AddressHeader:          111,
		P2SHHeader:             196,
		HDPrivateKeyID:         []byte{0x04, 0x35, 0x83, 0x94},
		HDPublicKeyID:          []byte{0x04, 0x35, 0x87, 0xcf},
	}
	//LitecoinMain is params for litecoin main net.
	LitecoinMain = &address.Params{
		DumpedPrivateKeyHeader: []byte{176},
		AddressHeader:          48,
		P2SHHeader:             50,
		HDPrivateKeyID:         []byte{0x04, 0x88, 0xad, 0xe4},
		HDPublicKeyID:          []byte{0x04, 0x88, 0xb2, 0x1e},
	}
	//LitecoinTest is params for litecoin test net.
	LitecoinTest = &address.Params{
		DumpedPrivateKeyHeader: []byte{239},
		AddressHeader:          111,
		P2SHHeader:             58,
		HDPrivateKeyID:         []byte{0x04, 0x35, 0x83, 0x94},
		HDPublicKeyID:          []byte{0x04, 0x35, 0x87, 0xcf},
	}
)
View Source
var (
	ErrAccountBucketNotExisted = fmt.Errorf("account bucket is not existed")
	ErrUTXOBucketNotExisted    = fmt.Errorf("utxo bucket is not existed")
)
View Source
var (
	ErrNotEnoughCoin   = fmt.Errorf("not enough of coins in the wallet")
	ErrNilAccountStore = fmt.Errorf("no account store is set")
)
View Source
var CoinFee = map[CoinType]uint64{
	BTC: 1000,
	LTC: 10000,
}
View Source
var CoinMap = map[CoinType]uint32{
	BTC: 0,
	LTC: 2,
}
View Source
var CoinParams = map[CoinType]map[Test]*address.Params{
	BTC: {
		// contains filtered or unexported fields
	},
	LTC: {
		// contains filtered or unexported fields
	},
}

Functions

This section is empty.

Types

type AccountStore

type AccountStore interface {
	GetLastIndex() (uint64, error)
	SetLastIndex(uint64) error
	GetAllUTXO() (map[string]tx.UTXOs, error)
	GetUTXO(address string) (tx.UTXOs, error)
	SetUTXO(address string, utxo tx.UTXOs) error
	Close()
}

type BoltAccountStore

type BoltAccountStore struct {
	// contains filtered or unexported fields
}

BoltAccountStore is an account store using boltdb. The wallet data is organized as follow: + bucket (pubkey of coin_account)

  • bucket ("utxo")
  • address : txs
  • lastIndex : varint

func NewBoltAccountStore

func NewBoltAccountStore(filename, account string) (*BoltAccountStore, error)

func (BoltAccountStore) Close

func (b BoltAccountStore) Close()

func (BoltAccountStore) GetAllUTXO

func (b BoltAccountStore) GetAllUTXO() (map[string]tx.UTXOs, error)

func (BoltAccountStore) GetLastIndex

func (b BoltAccountStore) GetLastIndex() (uint64, error)

func (BoltAccountStore) GetUTXO

func (b BoltAccountStore) GetUTXO(address string) (tx.UTXOs, error)

func (BoltAccountStore) SetLastIndex

func (b BoltAccountStore) SetLastIndex(index uint64) error

func (BoltAccountStore) SetUTXO

func (b BoltAccountStore) SetUTXO(address string, utxos tx.UTXOs) error

type CoinAccount

type CoinAccount struct {
	CoinType CoinType
	Test     Test
	Key      *address.ExtendedKey
	// contains filtered or unexported fields
}

CoinAccount is the root struct for manipulate coins.

func (CoinAccount) Address

func (c CoinAccount) Address(i uint32, change bool) (string, error)

Address returns a coin address

func (*CoinAccount) Close added in v0.6.1

func (c *CoinAccount) Close()

func (CoinAccount) Discover

func (c CoinAccount) Discover() error

func (CoinAccount) GetBalance

func (c CoinAccount) GetBalance() (uint64, error)

func (CoinAccount) NewChangeAddr

func (c CoinAccount) NewChangeAddr() (string, error)

func (CoinAccount) NewExternalAddr

func (c CoinAccount) NewExternalAddr() (string, error)

func (CoinAccount) Send

func (c CoinAccount) Send(sends []*tx.Send, customData []byte, fee uint64) (string, string, error)

func (*CoinAccount) SetAgent

func (c *CoinAccount) SetAgent(a agent.CoinAgent)

func (CoinAccount) String

func (c CoinAccount) String() string

String returns the identifier of an account.

type CoinType

type CoinType string
const (
	BTC CoinType = "BTC"
	LTC CoinType = "LTC"
)

type Test

type Test bool

type UnspentFunds added in v0.7.0

type UnspentFunds struct {
	TxIn        []*wire.TxIn
	TotalAmount uint64
	UTXOs       tx.UTXOs
}

type Wallet

type Wallet struct {
	// contains filtered or unexported fields
}

func New

func New(seed []byte, dataFile string) *Wallet

func (Wallet) CoinAccount

func (w Wallet) CoinAccount(ct CoinType, test Test, account uint32) (*CoinAccount, error)

CoinAccount returns an extended account base on BIP44 with the coin type and the account index being specified.

Directories

Path Synopsis
base85 → bytes and decode the address version substitute for broken decoder in bitgoin/address
base85 → bytes and decode the address version substitute for broken decoder in bitgoin/address
command

Jump to

Keyboard shortcuts

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