uzlocoin

package
v0.0.0-...-87acc28 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MainNet represents the main bitcoin network.
	MainUzlocoinNet wire.BitcoinNet = 0x504852 // PHR
	TestUzlocoinNet wire.BitcoinNet = 0x545048 // TP
)
View Source
const (
	// RedeemP2PKHSigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a compressed P2PKH output.
	// It is calculated as:
	//
	//   - OP_DATA_73
	//   - 72 bytes DER signature + 1 byte sighash
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	RedeemP2PKHSigScriptSize = 1 + 73 + 1 + 33

	// RedeemP2SHMultisigSigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a 2 of 3 P2SH multisig output with compressed keys.
	// It is calculated as:
	//
	//   - OP_0
	//   - OP_DATA_72
	//   - 72 bytes DER signature
	//   - OP_DATA_72
	//   - 72 bytes DER signature
	//   - OP_PUSHDATA
	//   - OP_2
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP3
	//   - OP_CHECKMULTISIG
	RedeemP2SH2of3MultisigSigScriptSize = 1 + 1 + 72 + 1 + 72 + 1 + 1 + 1 + 33 + 1 + 33 + 1 + 33 + 1 + 1

	// RedeemP2SH1of2MultisigSigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a 1 of 2 P2SH multisig output with compressed keys.
	// It is calculated as:
	//
	//   - OP_0
	//   - OP_DATA_72
	//   - 72 bytes DER signature
	//   - OP_PUSHDATA
	//   - OP_1
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP2
	//   - OP_CHECKMULTISIG
	RedeemP2SH1of2MultisigSigScriptSize = 1 + 1 + 72 + 1 + 1 + 1 + 33 + 1 + 33 + 1 + 1

	// RedeemP2SHMultisigTimelock1SigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a compressed P2SH timelocked multisig using the timeout.
	// It is calculated as:
	//
	//   - OP_DATA_72
	//   - 72 bytes DER signature
	//   - OP_0
	//   - OP_PUSHDATA
	//   - OP_IF
	//   - OP_2
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP3
	//   - OP_CHECKMULTISIG
	//   - OP_ELSE
	//   - OP_PUSHDATA
	//   - 2 byte block height
	//   - OP_CHECKSEQUENCEVERIFY
	//   - OP_DROP
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_CHECKSIG
	//   - OP_ENDIF
	RedeemP2SHMultisigTimelock1SigScriptSize = 1 + 72 + 1 + 1 + 1 + 1 + 1 + 33 + 1 + 33 + 1 + 33 + 1 + 1 + 1 + 1 + 2 + 1 + 1 + 1 + 33 + 1 + 1

	// RedeemP2SHMultisigTimelock2SigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a compressed P2SH timelocked multisig without using the timeout.
	// It is calculated as:
	//
	//   - OP_0
	//   - OP_DATA_72
	//   - 72 bytes DER signature
	//   - OP_DATA_72
	//   - 72 bytes DER signature
	//   - OP_1
	//   - OP_PUSHDATA
	//   - OP_IF
	//   - OP_2
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP3
	//   - OP_CHECKMULTISIG
	//   - OP_ELSE
	//   - OP_PUSHDATA
	//   - 2 byte block height
	//   - OP_CHECKSEQUENCEVERIFY
	//   - OP_DROP
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_CHECKSIG
	//   - OP_ENDIF
	RedeemP2SHMultisigTimelock2SigScriptSize = 1 + 1 + 72 + +1 + 72 + 1 + 1 + 1 + 1 + 1 + 33 + 1 + 33 + 1 + 33 + 1 + 1 + 1 + 1 + 2 + 1 + 1 + 1 + 33 + 1 + 1

	// P2PKHPkScriptSize is the size of a transaction output script that
	// pays to a compressed pubkey hash.  It is calculated as:
	//
	//   - OP_DUP
	//   - OP_HASH160
	//   - OP_DATA_20
	//   - 20 bytes pubkey hash
	//   - OP_EQUALVERIFY
	//   - OP_CHECKSIG
	P2PKHPkScriptSize = 1 + 1 + 1 + 20 + 1 + 1

	// RedeemP2PKHInputSize is the worst case (largest) serialize size of a
	// transaction input redeeming a compressed P2PKH output.  It is
	// calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte script len
	//   - signature script
	//   - 4 bytes sequence
	RedeemP2PKHInputSize = 32 + 4 + 1 + RedeemP2PKHSigScriptSize + 4

	// RedeemP2SH2of3MultisigInputSize is the worst case (largest) serialize size of a
	// transaction input redeeming a compressed P2SH 2 of 3 multisig output.  It is
	// calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte script len
	//   - 4 bytes sequence
	///  - witness discounted signature script
	RedeemP2SH2of3MultisigInputSize = 32 + 4 + 1 + 4 + (RedeemP2SH2of3MultisigSigScriptSize / 4)

	// RedeemP2SH1of2MultisigInputSize is the worst case (largest) serialize size of a
	// transaction input redeeming a compressed P2SH 2 of 3 multisig output.  It is
	// calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte script len
	//   - 4 bytes sequence
	///  - witness discounted signature script
	RedeemP2SH1of2MultisigInputSize = 32 + 4 + 1 + 4 + (RedeemP2SH1of2MultisigSigScriptSize / 4)

	// RedeemP2SHMultisigTimelock1InputSize is the worst case (largest) serialize size of a
	// transaction input redeeming a compressed p2sh timelocked multig output with using the timeout.  It is
	// calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte script len
	//   - 4 bytes sequence
	///  - witness discounted signature script
	RedeemP2SHMultisigTimelock1InputSize = 32 + 4 + 1 + 4 + (RedeemP2SHMultisigTimelock1SigScriptSize / 4)

	// RedeemP2SHMultisigTimelock2InputSize is the worst case (largest) serialize size of a
	// transaction input redeeming a compressed P2SH timelocked multisig output without using the timeout.  It is
	// calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte script len
	//   - 4 bytes sequence
	///  - witness discounted signature script
	RedeemP2SHMultisigTimelock2InputSize = 32 + 4 + 1 + 4 + (RedeemP2SHMultisigTimelock2SigScriptSize / 4)

	// P2PKHOutputSize is the serialize size of a transaction output with a
	// P2PKH output script.  It is calculated as:
	//
	//   - 8 bytes output value
	//   - 1 byte compact int encoding value 25
	//   - 25 bytes P2PKH output script
	P2PKHOutputSize = 8 + 1 + P2PKHPkScriptSize
)

Worst case script and input/output size estimates.

View Source
const SatoshiPerPHR int64 = 100000000

Variables

View Source
var (
	UzlocoinCurrencyDefinition = wi.CurrencyDefinition{
		Code:         "PHR",
		Divisibility: 8,
	}
)
View Source
var UzlocoinMainNetParams = chaincfg.Params{
	Name:        "mainUzlocoin",
	Net:         MainUzlocoinNet,
	DefaultPort: "6331",
	DNSSeeds: []chaincfg.DNSSeed{
		{"45.93.100.49", true},
		{"seeder.unibankwallet.com", true},
	},

	GenesisBlock:     nil,
	GenesisHash:      nil,
	PowLimit:         mainPowLimit,
	PowLimitBits:     0x207fffff,
	BIP0034Height:    0,
	BIP0065Height:    0,
	BIP0066Height:    0,
	CoinbaseMaturity: 50,
	TargetTimespan:   time.Minute,

	TargetTimePerBlock:       time.Minute,
	RetargetAdjustmentFactor: 4,
	ReduceMinDifficulty:      false,
	MinDiffReductionTime:     0,
	GenerateSupported:        true,

	Checkpoints: []chaincfg.Checkpoint{},

	RelayNonStdTxs: false,

	Bech32HRPSegwit: "uz",

	PubKeyHashAddrID: 0x37,
	ScriptHashAddrID: 0x0d,
	PrivateKeyID:     0xd4,

	HDPrivateKeyID: [4]byte{0x02, 0x2d, 0x25, 0x33},
	HDPublicKeyID:  [4]byte{0x02, 0x21, 0x31, 0x2b},

	HDCoinType: 0x800001bc,
}
View Source
var UzlocoinTestNetParams = chaincfg.Params{
	Name:        "testnetUzlocoin",
	Net:         TestUzlocoinNet,
	DefaultPort: "11773",
	DNSSeeds:    []chaincfg.DNSSeed{},

	GenesisBlock:             nil,
	GenesisHash:              nil,
	PowLimit:                 mainPowLimit,
	PowLimitBits:             0x207fffff,
	BIP0034Height:            0,
	BIP0065Height:            0,
	BIP0066Height:            0,
	CoinbaseMaturity:         50,
	TargetTimespan:           time.Minute,
	TargetTimePerBlock:       time.Minute,
	RetargetAdjustmentFactor: 4,
	ReduceMinDifficulty:      false,
	MinDiffReductionTime:     0,
	GenerateSupported:        true,
	Checkpoints:              []chaincfg.Checkpoint{},
	RelayNonStdTxs:           false,
	Bech32HRPSegwit:          "tp",

	PubKeyHashAddrID: 0x8B,
	ScriptHashAddrID: 0x13,
	PrivateKeyID:     0xEF,

	HDPrivateKeyID: [4]byte{0x3a, 0x80, 0x61, 0xa0},
	HDPublicKeyID:  [4]byte{0x3a, 0x80, 0x58, 0x37},

	HDCoinType: 0x80000001,
}

Functions

func EstimateSerializeSize

func EstimateSerializeSize(inputCount int, txOuts []*wire.TxOut, addChangeOutput bool, inputType InputType) int

EstimateSerializeSize returns a worst case serialize size estimate for a signed transaction that spends inputCount number of compressed P2PKH outputs and contains each transaction output from txOuts. The estimated size is incremented for an additional P2PKH change output if addChangeOutput is true.

func NormalizeCurrencyCode

func NormalizeCurrencyCode(currencyCode string) string

NormalizeCurrencyCode standardizes the format for the given currency code

func SumOutputSerializeSizes

func SumOutputSerializeSizes(outputs []*wire.TxOut) (serializeSize int)

SumOutputSerializeSizes sums up the serialized size of the supplied outputs.

Types

type CMCDecoder

type CMCDecoder struct{}

empty structs to tag the different ExchangeRateDecoder implementations

type CoinGeckoDecoder

type CoinGeckoDecoder struct{}

type ExchangeRateDecoder

type ExchangeRateDecoder interface {
	// contains filtered or unexported methods
}

type ExchangeRateProvider

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

type InputType

type InputType int
const (
	P2PKH InputType = iota
	P2SH_1of2_Multisig
	P2SH_2of3_Multisig
	P2SH_Multisig_Timelock_1Sig
	P2SH_Multisig_Timelock_2Sigs
)

type PriceFetcher

type PriceFetcher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewUzlocoinPriceFetcher

func NewUzlocoinPriceFetcher(dialer proxy.Dialer) *PriceFetcher

func (*PriceFetcher) GetAllRates

func (b *PriceFetcher) GetAllRates(cacheOK bool) (map[string]float64, error)

func (*PriceFetcher) GetExchangeRate

func (b *PriceFetcher) GetExchangeRate(currencyCode string) (float64, error)

func (*PriceFetcher) GetLatestRate

func (b *PriceFetcher) GetLatestRate(currencyCode string) (float64, error)

func (*PriceFetcher) Run

func (b *PriceFetcher) Run()

func (*PriceFetcher) UnitsPerCoin

func (b *PriceFetcher) UnitsPerCoin() int64

type UzlocoinWallet

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

UzlocoinWallet represents a wallet based on JSON-RPC and Bitcoind

func NewUzlocoinWallet

func NewUzlocoinWallet(cfg config.CoinConfig, mnemonic string, params *chaincfg.Params, proxy proxy.Dialer, cache cache.Cacher, disableExchangeRates bool) (*UzlocoinWallet, error)

NewUzlocoinWallet creates a new wallet given

func (*UzlocoinWallet) AddTransactionListener

func (w *UzlocoinWallet) AddTransactionListener(callback func(wallet.TransactionCallback))

AddTransactionListener adds a listener for any wallet transactions

func (*UzlocoinWallet) AddWatchedAddresses

func (w *UzlocoinWallet) AddWatchedAddresses(addrs ...btc.Address) error

func (*UzlocoinWallet) AddressToScript

func (w *UzlocoinWallet) AddressToScript(addr btc.Address) ([]byte, error)

AddressToScript returns the script for a given address

func (*UzlocoinWallet) AssociateTransactionWithOrder

func (w *UzlocoinWallet) AssociateTransactionWithOrder(cb wi.TransactionCallback)

AssociateTransactionWithOrder used for ORDER_PAYMENT message

func (*UzlocoinWallet) Balance

Balance returns the total balance of our addresses

func (*UzlocoinWallet) Broadcast

func (w *UzlocoinWallet) Broadcast(tx *wire.MsgTx) error

Broadcast a transaction to the network

func (*UzlocoinWallet) BumpFee

func (w *UzlocoinWallet) BumpFee(txid chainhash.Hash) (*chainhash.Hash, error)

BumpFee attempts to bump the fee for a transaction

func (*UzlocoinWallet) ChainTip

func (w *UzlocoinWallet) ChainTip() (uint32, chainhash.Hash)

ChainTip returns the tip of the active blockchain

func (*UzlocoinWallet) ChildKey

func (w *UzlocoinWallet) ChildKey(keyBytes []byte, chaincode []byte, isPrivateKey bool) (*hd.ExtendedKey, error)

func (*UzlocoinWallet) Close

func (w *UzlocoinWallet) Close()

Close closes the rpc wallet connection

func (*UzlocoinWallet) CreateMultisigSignature

func (w *UzlocoinWallet) CreateMultisigSignature(ins []wi.TransactionInput, outs []wi.TransactionOutput, key *hd.ExtendedKey, redeemScript []byte, feePerByte big.Int) ([]wi.Signature, error)

func (*UzlocoinWallet) CurrencyCode

func (w *UzlocoinWallet) CurrencyCode() string

CurrencyCode returns the currency code of the wallet

func (*UzlocoinWallet) CurrentAddress

func (w *UzlocoinWallet) CurrentAddress(purpose wallet.KeyPurpose) btc.Address

CurrentAddress returns an unused address

func (*UzlocoinWallet) DecodeAddress

func (w *UzlocoinWallet) DecodeAddress(addr string) (btc.Address, error)

DecodeAddress decodes an address string to an address using the wallet's chain parameters

func (*UzlocoinWallet) DumpTables

func (w *UzlocoinWallet) DumpTables(wr io.Writer)

func (*UzlocoinWallet) EstimateFee

func (w *UzlocoinWallet) EstimateFee(ins []wi.TransactionInput, outs []wi.TransactionOutput, feePerByte big.Int) big.Int

EstimateFee estimates the fee of a transaction

func (*UzlocoinWallet) EstimateSpendFee

func (w *UzlocoinWallet) EstimateSpendFee(amount big.Int, feeLevel wi.FeeLevel) (big.Int, error)

func (*UzlocoinWallet) ExchangeRates

func (w *UzlocoinWallet) ExchangeRates() wallet.ExchangeRates

func (*UzlocoinWallet) GenerateMultisigScript

func (w *UzlocoinWallet) GenerateMultisigScript(keys []hd.ExtendedKey, threshold int, timeout time.Duration, timeoutKey *hd.ExtendedKey) (addr btc.Address, redeemScript []byte, err error)

GenerateMultisigScript generates a script representing a multisig wallet

func (*UzlocoinWallet) GetConfirmations

func (w *UzlocoinWallet) GetConfirmations(txid chainhash.Hash) (uint32, uint32, error)

GetConfirmations returns the number of confirmations and the block number where the transaction was confirmed

func (*UzlocoinWallet) GetFeePerByte

func (w *UzlocoinWallet) GetFeePerByte(feeLevel wi.FeeLevel) big.Int

GetFeePerByte gets the fee in pSAT per byte

func (*UzlocoinWallet) GetTransaction

func (w *UzlocoinWallet) GetTransaction(txid chainhash.Hash) (wallet.Txn, error)

GetTransaction returns the transaction given by a transaction hash

func (*UzlocoinWallet) HasKey

func (w *UzlocoinWallet) HasKey(addr btc.Address) bool

HasKey returns true if we have the private key for a given address

func (*UzlocoinWallet) IsDust

func (w *UzlocoinWallet) IsDust(amount big.Int) bool

IsDust determines if an amount is considered dust

func (*UzlocoinWallet) MasterPrivateKey

func (w *UzlocoinWallet) MasterPrivateKey() *hd.ExtendedKey

MasterPrivateKey returns the wallet's master private key

func (*UzlocoinWallet) MasterPublicKey

func (w *UzlocoinWallet) MasterPublicKey() *hd.ExtendedKey

MasterPublicKey returns the wallet's key used to derive public keys

func (*UzlocoinWallet) Multisign

func (w *UzlocoinWallet) Multisign(ins []wi.TransactionInput, outs []wi.TransactionOutput, sigs1 []wi.Signature, sigs2 []wi.Signature, redeemScript []byte, feePerByte big.Int, broadcast bool) ([]byte, error)

func (*UzlocoinWallet) NewAddress

func (w *UzlocoinWallet) NewAddress(purpose wallet.KeyPurpose) btc.Address

NewAddress creates a new address

func (*UzlocoinWallet) Params

func (w *UzlocoinWallet) Params() *chaincfg.Params

func (*UzlocoinWallet) ReSyncBlockchain

func (w *UzlocoinWallet) ReSyncBlockchain(fromDate time.Time)

ReSyncBlockchain resyncs the addresses used by the SPV wallet

func (*UzlocoinWallet) ScriptToAddress

func (w *UzlocoinWallet) ScriptToAddress(script []byte) (btc.Address, error)

ScriptToAddress converts a script to an address

func (*UzlocoinWallet) Spend

func (w *UzlocoinWallet) Spend(amount big.Int, addr btc.Address, feeLevel wi.FeeLevel, referenceID string, spendAll bool) (*chainhash.Hash, error)

Spend spends an amount from an address with a given fee level

func (*UzlocoinWallet) Start

func (w *UzlocoinWallet) Start()

Start sets up the rpc wallet

func (*UzlocoinWallet) SweepAddress

func (w *UzlocoinWallet) SweepAddress(ins []wallet.TransactionInput, address *btc.Address, key *hd.ExtendedKey, redeemScript *[]byte, feeLevel wallet.FeeLevel) (*chainhash.Hash, error)

SweepAddress sweeps any UTXOs from an address in a single transaction

func (*UzlocoinWallet) Transactions

func (w *UzlocoinWallet) Transactions() ([]wallet.Txn, error)

Transactions returns all of the transactions relating to any of our addresses

Jump to

Keyboard shortcuts

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