btc

package
v0.0.0-...-035b7fa Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2021 License: GPL-3.0 Imports: 39 Imported by: 1

Documentation

Overview

* Copyright (C) 2020 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.

* Copyright (C) 2020 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.

* Copyright (C) 2020 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildData

func BuildData(toChainId uint64, ccFee int64, toAddr string) ([]byte, error)

func GetAccountByPassword

func GetAccountByPassword(sdk *poly_go_sdk.PolySdk, path string, pwd []byte) (
	*poly_go_sdk.Account, error)

func HexStringReverse

func HexStringReverse(value string) string

func LenOfSyncMap

func LenOfSyncMap(sm *sync.Map) int64

func RandomInt64

func RandomInt64(min, max int64) int64

func ReverseHexString

func ReverseHexString(b string) string

func SetUpPoly

func SetUpPoly(poly *poly_go_sdk.PolySdk, rpcAddr string) error

Types

type BtcInvoker

type BtcInvoker struct {
	RChain      *poly_go_sdk.PolySdk
	RChainAcc   *poly_go_sdk.Account
	FromChainId int32
	BtcCli      *RestCli
	Signer      *BtcSigner
}

func NewBtcInvoker

func NewBtcInvoker(rpc, wallet, pwd, btcRpc, btcUser, btcPwd, privk string) (*BtcInvoker, error)

func (*BtcInvoker) BindBtcTxParam

func (invoker *BtcInvoker) BindBtcTxParam(feeRate, minChange uint64, vendor *Vendor) (common.Uint256, error)

func (*BtcInvoker) BindBtcxWithVendor

func (invoker *BtcInvoker) BindBtcxWithVendor(btcx string, btcxChainId uint64, vendor *Vendor) (common.Uint256, error)

func (*BtcInvoker) GenerateVendor

func (invoker *BtcInvoker) GenerateVendor(n, require int) (*Vendor, error)

* Generate 3/5, 4/7 Vendors

func (*BtcInvoker) GetAccInfo

func (invoker *BtcInvoker) GetAccInfo() (string, error)

type BtcItem

type BtcItem struct {
	Item *ToBtcItem
	Mtx  *wire.MsgTx
}

type BtcSigner

type BtcSigner struct {
	WIF     *btcutil.WIF
	Address string
}

func NewBtcSigner

func NewBtcSigner(privateKey string) (*BtcSigner, error)

type BuildCrossChainTxParam

type BuildCrossChainTxParam struct {
	Inputs       []btcjson.TransactionInput
	Changes      map[string]float64 //pay to pubK
	ToMultiValue float64
	Redeem       string
	Locktime     *int64
	PrevPkScript []byte
	Privk        *btcec.PrivateKey
	NetParam     *chaincfg.Params
	Data         []byte
}

type Builder

type Builder struct {
	NetParam     *chaincfg.Params
	PrevPkScript []byte
	PrivKey      *btcec.PrivateKey
	PubKey       *btcec.PublicKey
	Tx           *wire.MsgTx
	IsSigned     bool
	RedeemScript []byte
	Privks       map[string]*btcec.PrivateKey
}

func NewBuilder

func NewBuilder(param *BuildCrossChainTxParam) (b *Builder, err error)

func (*Builder) BuildSignedTx

func (builder *Builder) BuildSignedTx() error

locking

func (*Builder) LookUpKey

func (builder *Builder) LookUpKey(addr btcutil.Address) (*btcec.PrivateKey, bool, error)

type FromBtcItem

type FromBtcItem struct {
	BtcTxid string
	OntAddr string
	Value   int64
}

func (*FromBtcItem) String

func (item *FromBtcItem) String() string

type Request

type Request struct {
	Jsonrpc string        `json:"jsonrpc"`
	Method  string        `json:"method"`
	Params  []interface{} `json:"params"`
	Id      int           `json:"id"`
}

type Response

type Response struct {
	Result interface{}       `json:"result"`
	Error  *btcjson.RPCError `json:"error"` //maybe wrong
	Id     int               `json:"id"`
}

type RestCli

type RestCli struct {
	Addr string
	Cli  *http.Client
}

Get tx in block; Get proof;

func NewRestCli

func NewRestCli(addr, user, pwd string) *RestCli

func (*RestCli) BroadcastTx

func (cli *RestCli) BroadcastTx(tx string) (string, error)

func (*RestCli) GenerateToAddr

func (cli *RestCli) GenerateToAddr(n int, addr string) ([]string, error)

func (*RestCli) GetBlockCount

func (cli *RestCli) GetBlockCount() (int64, error)

func (*RestCli) GetBlockHeight

func (cli *RestCli) GetBlockHeight(hash string) (int32, error)

func (*RestCli) GetCurrentHeightAndHash

func (cli *RestCli) GetCurrentHeightAndHash() (int32, string, error)

func (*RestCli) GetHeader

func (cli *RestCli) GetHeader(h int32) (*wire.BlockHeader, error)

func (*RestCli) GetMempoolInfo

func (cli *RestCli) GetMempoolInfo() (int32, error)

func (*RestCli) GetProof

func (cli *RestCli) GetProof(txids []string) (string, error)

func (*RestCli) GetRawTransaction

func (cli *RestCli) GetRawTransaction(txid string) (string, error)

func (*RestCli) GetTxOutVal

func (cli *RestCli) GetTxOutVal(txid string, idx uint32) (int64, error)

func (*RestCli) GetTxsInBlock

func (cli *RestCli) GetTxsInBlock(hash string) ([]*wire.MsgTx, string, error)

func (*RestCli) ImportAddress

func (cli *RestCli) ImportAddress(addr string) error

func (*RestCli) ListUnspent

func (cli *RestCli) ListUnspent(minConfs, maxConfs int64, addr string) ([]*Utxo, error)

func (*RestCli) SendRawTx

func (cli *RestCli) SendRawTx(rawTx string) (string, error)

type ToBtcItem

type ToBtcItem struct {
	OntTxid string
	BtcAddr string
	Value   int64
}

type Utxo

type Utxo struct {
	Txid         string
	Vout         uint32
	ScriptPubKey string
	Amount       int64
	Confs        int64
}

func SelectUtxos

func SelectUtxos(utxos []*Utxo, value int64) ([]*Utxo, int64, error)

func (*Utxo) String

func (u *Utxo) String() string

type UtxoItem

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

type UtxoList

type UtxoList []*UtxoItem

func (UtxoList) Len

func (ul UtxoList) Len() int

func (UtxoList) Less

func (ul UtxoList) Less(i, j int) bool

func (UtxoList) Swap

func (ul UtxoList) Swap(i, j int)

type Vendor

type Vendor struct {
	PrivateKeys []*btcutil.WIF
	AddressSet  []*btcutil.AddressPubKey
	Redeem      []byte
	HashKey     []byte
	P2shAddr    *btcutil.AddressScriptHash
	P2wshAddr   *btcutil.AddressWitnessScriptHash
}

func NewVendorFromConfig

func NewVendorFromConfig() (*Vendor, error)

func (*Vendor) EncryptPrivateKeys

func (v *Vendor) EncryptPrivateKeys(file, pwd string) ([]string, error)

func (*Vendor) UpdateConfigFile

func (v *Vendor) UpdateConfigFile(file, suffix, privkFile, pwd string) error

Jump to

Keyboard shortcuts

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