Documentation ¶
Index ¶
- Constants
- Variables
- func AddressPubKeyFromString(pubKey string, net *chaincfg.Params) (*jaxutil.AddressPubKey, error)
- func DecodeScript(script []byte, net *chaincfg.Params) (*jaxjson.DecodeScriptResult, error)
- func DecodeTx(hexTx string) (*wire.MsgTx, error)
- func EncodeTx(tx *wire.MsgTx) string
- func EstimateFee(inCount, outCount int, feeRate int64, addChange bool, shardID uint32) int64
- func EstimateFeeForTx(tx *wire.MsgTx, feeRate int64, addChange bool, shardID uint32) int64
- func SendTx(txMan *TxMan, senderKP *KeyData, shardID uint32, destination string, ...) (string, error)
- func SetRedeemScript(utxo txmodels.UTXO, redeemScript string, net *chaincfg.Params) (txmodels.UTXO, error)
- func TxToJson(mtx *wire.MsgTx, chainParams *chaincfg.Params) jaxjson.TxRawDecodeResult
- func WaitForTx(rpcClient *rpcclient.Client, shardID uint32, txHash string, _ uint32) error
- type FeeProviderFunc
- type GetTxOutFunc
- type InMemoryKeystore
- func (kp *InMemoryKeystore) Address() jaxutil.Address
- func (kp *InMemoryKeystore) AddressPubKey() jaxutil.Address
- func (kp *InMemoryKeystore) AddressPubKeyHash() jaxutil.Address
- func (kp *InMemoryKeystore) AddressString() string
- func (*InMemoryKeystore) FromKeyData(data *KeyData) KeyStoreProvider
- func (kp *InMemoryKeystore) GetKey(address jaxutil.Address) (*btcec.PrivateKey, bool, error)
- func (kp *InMemoryKeystore) KeyData() *KeyData
- type KeyData
- type KeyStoreProvider
- type ManagerCfg
- type MultiSigAddress
- type MultiSigLockAddress
- type NewTxClient
- type NewUTXOProvider
- type NodeRPC
- type Operator
- func (app *Operator) AddSignatureToTx(signer KeyData, txBody, redeemScript string) (*txmodels.Transaction, error)
- func (app *Operator) NewMultiSigSpendTx(signer KeyData, txHash, redeemScript string, outIndex uint32, ...) (*txmodels.Transaction, error)
- func (app *Operator) SpendUTXO(signer KeyData, txHash string, outIndex uint32, destination string, ...) (*txmodels.Transaction, error)
- func (app *Operator) UTXOByHash(txHash string, outIndex uint32, redeemScript string) (*txmodels.UTXO, error)
- type SingleUTXO
- type TxBuilder
- type TxClient
- type TxMan
- func (client *TxMan) AddSignatureToSwapTx(msgTx *wire.MsgTx, shards []uint32, redeemScripts ...string) (*wire.MsgTx, error)
- func (client *TxMan) AddSignatureToTx(msgTx *wire.MsgTx, redeemScripts ...string) (*wire.MsgTx, error)
- func (client *TxMan) CollectUTXO(address string, offset int64) (txmodels.UTXORows, int64, error)
- func (client *TxMan) CollectUTXOIndex(shardID uint32, offset int64, filter map[string]bool, ...) (*txmodels.UTXOIndex, int64, error)
- func (client *TxMan) CollectUTXOs(opts UTXOCollectorOpts) (map[uint32]txmodels.UTXORows, int64, error)
- func (client *TxMan) DecodeScript(script []byte) (*jaxjson.DecodeScriptResult, error)
- func (client *TxMan) DraftToSignedTx(data txmodels.DraftTx, postVerify bool) (*wire.MsgTx, error)
- func (client *TxMan) ForShard(shardID uint32) *TxMan
- func (client *TxMan) NetworkFee(shardID uint32) (int64, error)
- func (client *TxMan) NetworkFeeProvider(shardID uint32) (int64, int64, error)
- func (client *TxMan) NewEADRegistrationTx(amountToLock int64, utxoPrv UTXOProvider, destinationsScripts ...[]byte) (*txmodels.Transaction, error)
- func (client *TxMan) NewMultiSig2of2Address(firstPubKey, second string) (*MultiSigAddress, error)
- func (client *TxMan) NewSwapTx(spendingMap map[string]txmodels.UTXO, postVerify bool, redeemScripts ...string) (*txmodels.SwapTransaction, error)
- func (client *TxMan) NewTx(destination string, amount int64, utxoPrv UTXOProvider, ...) (*txmodels.Transaction, error)
- func (client *TxMan) RPC() *rpcclient.Client
- func (client *TxMan) SetKey(key *KeyData)
- func (client *TxMan) SignUTXOForTx(msgTx *wire.MsgTx, utxo txmodels.ShortUTXO, inIndex int, postVerify bool) (*wire.MsgTx, []byte, error)
- func (client *TxMan) WithKeys(key *KeyData) *TxMan
- type UTXOCollectorOpts
- type UTXOFromCSV
- type UTXOFromRows
- type UTXOProvider
Constants ¶
const (
OneCoin int64 = 100_000_000
)
Variables ¶
var ( TxInEstWeight = 180 // size of regular signed utxo TxOutEstWeight = 34 // simple output )
Functions ¶
func AddressPubKeyFromString ¶
func DecodeScript ¶
func EstimateFee ¶
func EstimateFeeForTx ¶
func SetRedeemScript ¶
Types ¶
type FeeProviderFunc ¶
FeeProviderFunc should return non-zero value either fee or feeRate rate. Static fee has main priority, otherwise, the fee will be calculated using feeRate.
type GetTxOutFunc ¶
type InMemoryKeystore ¶
type InMemoryKeystore struct {
// contains filtered or unexported fields
}
func (*InMemoryKeystore) Address ¶
func (kp *InMemoryKeystore) Address() jaxutil.Address
func (*InMemoryKeystore) AddressPubKey ¶
func (kp *InMemoryKeystore) AddressPubKey() jaxutil.Address
func (*InMemoryKeystore) AddressPubKeyHash ¶
func (kp *InMemoryKeystore) AddressPubKeyHash() jaxutil.Address
func (*InMemoryKeystore) AddressString ¶
func (kp *InMemoryKeystore) AddressString() string
func (*InMemoryKeystore) FromKeyData ¶
func (*InMemoryKeystore) FromKeyData(data *KeyData) KeyStoreProvider
func (*InMemoryKeystore) GetKey ¶
func (kp *InMemoryKeystore) GetKey(address jaxutil.Address) (*btcec.PrivateKey, bool, error)
type KeyData ¶
type KeyData struct { PrivateKey *btcec.PrivateKey Address jaxutil.Address AddressPubKey *jaxutil.AddressPubKey }
func NewKeyData ¶
type KeyStoreProvider ¶
type KeyStoreProvider interface { GetKey(jaxutil.Address) (*btcec.PrivateKey, bool, error) AddressPubKey() jaxutil.Address AddressPubKeyHash() jaxutil.Address Address() jaxutil.Address AddressString() string }
func NewInMemoryKeystore ¶
func NewInMemoryKeystore(secret string, net chaincfg.NetName) (KeyStoreProvider, error)
type ManagerCfg ¶
type ManagerCfg struct { Net string `json:"net" yaml:"net" toml:"net"` ShardID uint32 `json:"shard_id" yaml:"shard_id" toml:"shard_id"` RPC NodeRPC `json:"rpc" yaml:"rpc" toml:"rpc"` PrivateKey string `json:"private_key" yaml:"private_key" toml:"private_key"` }
func (*ManagerCfg) NetParams ¶
func (cfg *ManagerCfg) NetParams() *chaincfg.Params
type MultiSigAddress ¶
type MultiSigAddress struct { Address string `json:"address"` RedeemScript string `json:"redeemScript"` SignaturesRequired int `json:"signaturesRequired"` RawRedeemScript []byte `json:"-"` }
func MakeMultiSigScript ¶
type MultiSigLockAddress ¶
type MultiSigLockAddress struct { Address string `json:"address"` RefundPublicKey string `json:"refundPublicKey"` RefundDefferingPeriod int32 `json:"refundDefferingPeriod"` RedeemScript string `json:"redeemScript"` SignaturesRequired int `json:"signaturesRequired"` RawRedeemScript []byte `json:"-"` }
func MakeMultiSigLockAddress ¶
type NewTxClient ¶
type NewTxClient interface { SetKey(keystore KeyStoreProvider) WithKeys(keystore KeyStoreProvider) NewTxClient SetShard(shardID uint32) ForShard(shardID uint32) NewTxClient RPC() *rpcclient.Client NetworkFee() (int64, error) DecodeScript(script []byte) (*jaxjson.DecodeScriptResult, error) NewMultiSig2of2Address(firstPubKey, second string) (*MultiSigAddress, error) CollectUTXO(address string, offset int64) (txmodels.UTXORows, int64, error) CollectUTXOs(opts UTXOCollectorOpts) (map[uint32]txmodels.UTXORows, int64, error) CollectUTXOIndex(shardID uint32, offset int64, filter map[string]bool, index *txmodels.UTXOIndex) (*txmodels.UTXOIndex, int64, error) NewTx(tx TxBuilder) (*txmodels.Transaction, error) AddSignatureToSwapTx(msgTx *wire.MsgTx, shards []uint32, redeemScripts ...string) (*wire.MsgTx, error) AddSignatureToTx(msgTx *wire.MsgTx, redeemScripts ...string) (*wire.MsgTx, error) SignUTXOForTx(msgTx *wire.MsgTx, utxo txmodels.ShortUTXO, inIndex int, postVerify bool) ([]byte, error) }
type NewUTXOProvider ¶
type NewUTXOProvider interface { // SelectForAmount returns a list of txmodels.UTXO which satisfies the passed amount. SelectForAmount(amount int64, shardID uint32, addresses ...string) (txmodels.UTXORows, error) // GetForAmount returns a single txmodels.UTXO with Value GreaterOrEq passed amount. GetForAmount(amount int64, shardID uint32, addresses ...string) (*txmodels.UTXO, error) }
type Operator ¶
type Operator struct {
TxMan *TxMan
}
func NewOperator ¶
func NewOperator(config ManagerCfg) (Operator, error)
func (*Operator) AddSignatureToTx ¶
func (*Operator) NewMultiSigSpendTx ¶
func (*Operator) SpendUTXO ¶
func (app *Operator) SpendUTXO(signer KeyData, txHash string, outIndex uint32, destination string, amount int64) (*txmodels.Transaction, error)
SpendUTXO creates new transaction that spends UTXO with 'outIndex' from transaction with 'txHash'. Into new transactions will be added one Input and one or two Outputs, if 'amount' less than UTXO value.
type SingleUTXO ¶
UTXOFromRows is a wrapper for txmodels.UTXO to implement the UTXOProvider.
func (SingleUTXO) GetForAmount ¶
func (SingleUTXO) SelectForAmount ¶
type TxBuilder ¶
type TxBuilder interface { SetType(txVersion int32) TxBuilder SetShardID(shardID uint32) TxBuilder SwapTx() TxBuilder AddRedeemScripts(redeemScripts ...string) TxBuilder SetDestination(destination string, amount int64) TxBuilder SetDestinationWithUTXO(destination string, amount int64, utxo txmodels.UTXOs) TxBuilder SetDestinationAtShard(destination string, amount int64, shardID uint32) TxBuilder SetSenders(addresses ...string) TxBuilder SetChangeDestination(changeAddresses ...string) TxBuilder // SetFee sets static fee with. // If it set FeeProviderFunc result will be ignored SetFee(shardID uint32, fee int64) TxBuilder SetUTXOProvider(provider NewUTXOProvider) TxBuilder IntoTx(getFee FeeProviderFunc, kdb txscript.KeyDB) (*wire.MsgTx, error) }
func NewTxBuilder ¶
type TxClient ¶
type TxClient interface { SetKey(key *KeyData) WithKeys(key *KeyData) *TxMan ForShard(shardID uint32) *TxMan RPC() *rpcclient.Client CollectUTXO(address string, offset int64) (txmodels.UTXORows, int64, error) CollectUTXOs(opts UTXOCollectorOpts) (map[uint32]txmodels.UTXORows, int64, error) CollectUTXOIndex(shardID uint32, offset int64, filter map[string]bool, index *txmodels.UTXOIndex) (*txmodels.UTXOIndex, int64, error) NetworkFee() (int64, error) NewTx(destination string, amount int64, utxoPrv UTXOProvider, redeemScripts ...string) (*txmodels.Transaction, error) NewSwapTx(spendingMap map[string]txmodels.UTXO, postVerify bool, redeemScripts ...string) (*txmodels.SwapTransaction, error) DraftToSignedTx(data txmodels.DraftTx, postVerify bool) (*wire.MsgTx, error) AddSignatureToSwapTx(msgTx *wire.MsgTx, shards []uint32, redeemScripts ...string) (*wire.MsgTx, error) AddSignatureToTx(msgTx *wire.MsgTx, redeemScripts ...string) (*wire.MsgTx, error) SignUTXOForTx(msgTx *wire.MsgTx, utxo txmodels.ShortUTXO, inIndex int, postVerify bool) ([]byte, error) NewMultiSig2of2Address(firstPubKey, second string) (*MultiSigAddress, error) DecodeScript(script []byte) (*jaxjson.DecodeScriptResult, error) }
type TxMan ¶
func NewTxMan ¶
func NewTxMan(cfg ManagerCfg) (*TxMan, error)
func (*TxMan) AddSignatureToSwapTx ¶
func (*TxMan) AddSignatureToTx ¶
func (client *TxMan) AddSignatureToTx(msgTx *wire.MsgTx, redeemScripts ...string) (*wire.MsgTx, error)
AddSignatureToTx adds signature(s) to wire.TxIn in wire.MsgTx that spend coins with the txscript.MultiSigTy address. NOTE: this method don't work with SwapTx, use the AddSignatureToSwapTx.
func (*TxMan) CollectUTXO ¶
func (*TxMan) CollectUTXOIndex ¶
func (*TxMan) CollectUTXOs ¶
func (*TxMan) DecodeScript ¶
func (client *TxMan) DecodeScript(script []byte) (*jaxjson.DecodeScriptResult, error)
func (*TxMan) DraftToSignedTx ¶
func (*TxMan) NetworkFee ¶
NetworkFee returns Satoshi/bytes. To get size of the tx in bytes use chaindata.GetTransactionWeight(tx).
func (*TxMan) NetworkFeeProvider ¶
func (*TxMan) NewEADRegistrationTx ¶
func (client *TxMan) NewEADRegistrationTx(amountToLock int64, utxoPrv UTXOProvider, destinationsScripts ...[]byte) (*txmodels.Transaction, error)
func (*TxMan) NewMultiSig2of2Address ¶
func (client *TxMan) NewMultiSig2of2Address(firstPubKey, second string) (*MultiSigAddress, error)
func (*TxMan) NewSwapTx ¶
func (client *TxMan) NewSwapTx(spendingMap map[string]txmodels.UTXO, postVerify bool, redeemScripts ...string) (*txmodels.SwapTransaction, error)
DEPRECATED NewSwapTx creates new transaction with wire.TxVerCrossShardSwap version:
- data is a map of <Destination Address> => <Source txmodels.UTXO>.
- redeemScripts is optional, it allows to add proper signatures if source UTXO is a multisig address.
SwapTx is a special tx for atomic swap between chains. It can contain only TWO or FOUR inputs and TWO or FOUR outputs. wire.TxIn and wire.TxOut are strictly associated with each other by index. One pair corresponds to the one chain. The second is for another. | # | --- []TxIn ----- | --- | --- []TxOut ----- | # | | - | ---------------- | --- | ----------------- | - | | 0 | TxIn_0 ∈ Shard_X | --> | TxOut_0 ∈ Shard_X | 0 | | 1 | TxIn_1 ∈ Shard_Y | --> | TxOut_1 ∈ Shard_Y | 1 |
func (*TxMan) NewTx ¶
func (client *TxMan) NewTx(destination string, amount int64, utxoPrv UTXOProvider, redeemScripts ...string) (*txmodels.Transaction, error)
func (*TxMan) SignUTXOForTx ¶
func (client *TxMan) SignUTXOForTx(msgTx *wire.MsgTx, utxo txmodels.ShortUTXO, inIndex int, postVerify bool) (*wire.MsgTx, []byte, error)
SignUTXOForTx performs signing of UTXO, adds this signature to redeemTx. Method also supports signing of multiSig UTXOs, so just provide existing signature as prevScript
- redeemTx is a transaction that will be sent
- utxo is output that will be spent
- inIndex is an index, where placed this UTXO
- prevScript is a SignatureScript made by one or more previous key in case of multiSig UTXO, otherwise it nil
- postVerify say to check tx after signing
type UTXOCollectorOpts ¶
type UTXOFromCSV ¶
type UTXOFromCSV string
UTXOFromCSV is an implementation of UTXOProvider that collects txmodels.UTXORows from CSV file, value of UTXOFromCSV is a path to file.
func (UTXOFromCSV) GetForAmount ¶
func (UTXOFromCSV) SelectForAmount ¶
type UTXOFromRows ¶
UTXOFromRows is a wrapper for txmodels.UTXORows to implement the UTXOProvider.
func (UTXOFromRows) GetForAmount ¶
func (UTXOFromRows) SelectForAmount ¶
type UTXOProvider ¶
type UTXOProvider interface { // SelectForAmount returns a list of txmodels.UTXO which satisfies the passed amount. SelectForAmount(amount int64, shardID uint32, addresses ...string) (txmodels.UTXORows, error) // GetForAmount returns a single txmodels.UTXO with Value GreaterOrEq passed amount. GetForAmount(amount int64, shardID uint32, addresses ...string) (*txmodels.UTXO, error) }
UTXOProvider is provider that cat give list of txmodels.UTXO for provided amount.