wallet

package
v0.0.0-...-287e7ae Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeMaster = 0
	TypeStand  = 1 << 1
	TypeMulti  = 1 << 2
)
View Source
const (
	DriverName      = "sqlite3"
	DBName          = "./wallet.db"
	QueryHeightCode = 0
	ResetHeightCode = math.MaxUint32
)
View Source
const (
	CreateInfoTable = `CREATE TABLE IF NOT EXISTS Info (
				Name VARCHAR(20) NOT NULL PRIMARY KEY,
				Value BLOB
			);`
	CreateAddressesTable = `` /* 198-byte string literal not displayed */

	CreateUTXOsTable = `` /* 221-byte string literal not displayed */

)
View Source
const (
	OldWalletFile       = "wallet.dat"
	DefaultKeystoreFile = "keystore.dat"
)
View Source
const (
	DESTROY_ADDRESS = "0000000000000000000000000000000000"
)
View Source
const (
	KeystoreVersion = "1.0"
)
View Source
const MaxSignalQueueLen = 5

Variables

View Source
var SystemAssetId = getSystemAssetId()

Functions

func ExportKeystore

func ExportKeystore(name string, password []byte) ([]byte, error)

func GenerateKey

func GenerateKey(len uint16) []byte

func HandleSignal

func HandleSignal(handler func())

func ImportKeystore

func ImportKeystore(name string, password []byte, privateKey []byte) error

Types

type Address

type Address struct {
	Address      string
	ProgramHash  *Uint168
	RedeemScript []byte
	Type         int
}

func (*Address) TypeName

func (addr *Address) TypeName() string

type CrossChainOutput

type CrossChainOutput struct {
	Address           string
	Amount            *Fixed64
	CrossChainAddress string
}

type DataStore

type DataStore interface {
	sync.Locker
	DataSync

	CurrentHeight(height uint32) uint32

	AddAddress(programHash *Uint168, redeemScript []byte, addrType int) error
	DeleteAddress(programHash *Uint168) error
	GetAddressInfo(programHash *Uint168) (*Address, error)
	GetAddresses() ([]*Address, error)

	AddAddressUTXO(programHash *Uint168, utxo *UTXO) error
	DeleteUTXO(input *OutPoint) error
	GetAddressUTXOs(programHash *Uint168) ([]*UTXO, error)

	ResetDataStore() error
}

func OpenDataStore

func OpenDataStore() (DataStore, error)

type DataStoreImpl

type DataStoreImpl struct {
	sync.Mutex
	DataSync

	*sql.DB
}

func (*DataStoreImpl) AddAddress

func (store *DataStoreImpl) AddAddress(programHash *Uint168, redeemScript []byte, addrType int) error

func (*DataStoreImpl) AddAddressUTXO

func (store *DataStoreImpl) AddAddressUTXO(programHash *Uint168, utxo *UTXO) error

func (*DataStoreImpl) CurrentHeight

func (store *DataStoreImpl) CurrentHeight(height uint32) uint32

func (*DataStoreImpl) DeleteAddress

func (store *DataStoreImpl) DeleteAddress(programHash *Uint168) error

func (*DataStoreImpl) DeleteUTXO

func (store *DataStoreImpl) DeleteUTXO(op *OutPoint) error

func (*DataStoreImpl) GetAddressInfo

func (store *DataStoreImpl) GetAddressInfo(programHash *Uint168) (*Address, error)

func (*DataStoreImpl) GetAddressUTXOs

func (store *DataStoreImpl) GetAddressUTXOs(programHash *Uint168) ([]*UTXO, error)

func (*DataStoreImpl) GetAddresses

func (store *DataStoreImpl) GetAddresses() ([]*Address, error)

func (*DataStoreImpl) ResetDataStore

func (store *DataStoreImpl) ResetDataStore() error

type DataSync

type DataSync interface {
	SyncChainData()
}

func GetDataSync

func GetDataSync(dataStore DataStore) DataSync

type DataSyncImpl

type DataSyncImpl struct {
	DataStore
	// contains filtered or unexported fields
}

func (*DataSyncImpl) SyncChainData

func (sync *DataSyncImpl) SyncChainData()

type Keystore

type Keystore interface {
	ChangePassword(oldPassword, newPassword []byte) error

	GetPrivateKey() []byte
	GetPublicKey() *crypto.PublicKey
	GetRedeemScript() []byte
	GetProgramHash() *Uint168
	Address() string

	Sign(txn *Transaction) ([]byte, error)
}

func CreateKeystore

func CreateKeystore(name string, password []byte) (Keystore, error)

func OpenKeystore

func OpenKeystore(name string, password []byte) (Keystore, error)

type KeystoreFile

type KeystoreFile struct {
	sync.Mutex

	Version string

	IV                  string
	PasswordHash        string
	MasterKeyEncrypted  string
	PrivateKeyEncrypted string
	// contains filtered or unexported fields
}

func CreateKeystoreFile

func CreateKeystoreFile(name string) (*KeystoreFile, error)

func OpenFromOldVersion

func OpenFromOldVersion() (*KeystoreFile, error)

func OpenKeystoreFile

func OpenKeystoreFile(name string) (*KeystoreFile, error)

func (*KeystoreFile) GetIV

func (store *KeystoreFile) GetIV() ([]byte, error)

func (*KeystoreFile) GetMasterKeyEncrypted

func (store *KeystoreFile) GetMasterKeyEncrypted() ([]byte, error)

func (*KeystoreFile) GetPasswordHash

func (store *KeystoreFile) GetPasswordHash() ([]byte, error)

func (*KeystoreFile) GetPrivetKeyEncrypted

func (store *KeystoreFile) GetPrivetKeyEncrypted() ([]byte, error)

func (*KeystoreFile) LoadFromFile

func (store *KeystoreFile) LoadFromFile() error

func (*KeystoreFile) SaveToFile

func (store *KeystoreFile) SaveToFile() error

func (*KeystoreFile) SetIV

func (store *KeystoreFile) SetIV(iv []byte)

func (*KeystoreFile) SetMasterKeyEncrypted

func (store *KeystoreFile) SetMasterKeyEncrypted(masterKeyEncrypted []byte)

func (*KeystoreFile) SetPasswordHash

func (store *KeystoreFile) SetPasswordHash(passwordHash []byte)

func (*KeystoreFile) SetPrivateKeyEncrypted

func (store *KeystoreFile) SetPrivateKeyEncrypted(privateKeyEncrypted []byte)

type KeystoreImpl

type KeystoreImpl struct {
	sync.Mutex

	*KeystoreFile
	// contains filtered or unexported fields
}

func (*KeystoreImpl) Address

func (store *KeystoreImpl) Address() string

func (*KeystoreImpl) ChangePassword

func (store *KeystoreImpl) ChangePassword(oldPassword, newPassword []byte) error

func (*KeystoreImpl) GetPrivateKey

func (store *KeystoreImpl) GetPrivateKey() []byte

func (*KeystoreImpl) GetProgramHash

func (store *KeystoreImpl) GetProgramHash() *Uint168

func (*KeystoreImpl) GetPublicKey

func (store *KeystoreImpl) GetPublicKey() *crypto.PublicKey

func (*KeystoreImpl) GetRedeemScript

func (store *KeystoreImpl) GetRedeemScript() []byte

func (*KeystoreImpl) Sign

func (store *KeystoreImpl) Sign(txn *Transaction) ([]byte, error)

type SignalMap

type SignalMap map[os.Signal]func()

type SortableUTXOs

type SortableUTXOs []*UTXO

func (SortableUTXOs) Len

func (utxos SortableUTXOs) Len() int

func (SortableUTXOs) Less

func (utxos SortableUTXOs) Less(i, j int) bool

func (SortableUTXOs) Swap

func (utxos SortableUTXOs) Swap(i, j int)

type Transfer

type Transfer struct {
	Address string
	Amount  *Fixed64
}

type UTXO

type UTXO struct {
	Op       *OutPoint
	Amount   *Fixed64
	LockTime uint32
}

func SortUTXOs

func SortUTXOs(utxos []*UTXO) []*UTXO

type Wallet

type Wallet interface {
	DataStore

	Open(name string, password []byte) error
	ChangePassword(oldPassword, newPassword []byte) error

	AddStandardAccount(publicKey *crypto.PublicKey) (*Uint168, error)
	AddMultiSignAccount(M uint, publicKey ...*crypto.PublicKey) (*Uint168, error)

	CreateTransaction(fromAddress, toAddress string, amount, fee *Fixed64) (*Transaction, error)
	CreateLockedTransaction(fromAddress, toAddress string, amount, fee *Fixed64, lockedUntil uint32) (*Transaction, error)
	CreateMultiOutputTransaction(fromAddress string, fee *Fixed64, output ...*Transfer) (*Transaction, error)
	CreateLockedMultiOutputTransaction(fromAddress string, fee *Fixed64, lockedUntil uint32, output ...*Transfer) (*Transaction, error)
	CreateCrossChainTransaction(fromAddress, toAddress, crossChainAddress string, amount, fee *Fixed64) (*Transaction, error)

	Sign(name string, password []byte, transaction *Transaction) (*Transaction, error)

	Reset() error
}

type WalletImpl

type WalletImpl struct {
	DataStore
	Keystore
}

func Create

func Create(name string, password []byte) (*WalletImpl, error)

func GetWallet

func GetWallet() (*WalletImpl, error)

func (*WalletImpl) AddMultiSignAccount

func (wallet *WalletImpl) AddMultiSignAccount(M uint, publicKeys ...*crypto.PublicKey) (*Uint168, error)

func (*WalletImpl) AddStandardAccount

func (wallet *WalletImpl) AddStandardAccount(publicKey *crypto.PublicKey) (*Uint168, error)

func (*WalletImpl) CreateCrossChainTransaction

func (wallet *WalletImpl) CreateCrossChainTransaction(fromAddress, toAddress, crossChainAddress string, amount, fee *Fixed64) (*Transaction, error)

func (*WalletImpl) CreateLockedMultiOutputTransaction

func (wallet *WalletImpl) CreateLockedMultiOutputTransaction(fromAddress string, fee *Fixed64, lockedUntil uint32, outputs ...*Transfer) (*Transaction, error)

func (*WalletImpl) CreateLockedTransaction

func (wallet *WalletImpl) CreateLockedTransaction(fromAddress, toAddress string, amount, fee *Fixed64, lockedUntil uint32) (*Transaction, error)

func (*WalletImpl) CreateMultiOutputTransaction

func (wallet *WalletImpl) CreateMultiOutputTransaction(fromAddress string, fee *Fixed64, outputs ...*Transfer) (*Transaction, error)

func (*WalletImpl) CreateTransaction

func (wallet *WalletImpl) CreateTransaction(fromAddress, toAddress string, amount, fee *Fixed64) (*Transaction, error)

func (*WalletImpl) Open

func (wallet *WalletImpl) Open(name string, password []byte) error

func (*WalletImpl) Reset

func (wallet *WalletImpl) Reset() error

func (*WalletImpl) Sign

func (wallet *WalletImpl) Sign(name string, password []byte, txn *Transaction) (*Transaction, error)

Jump to

Keyboard shortcuts

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