btc

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddMultisigAddressResult

type AddMultisigAddressResult struct {
	Address      string `json:"address"`
	RedeemScript string `json:"redeemScript"`
}

AddMultisigAddressResult addmultisigaddressをcallしたresponseの型

type AddrsPrevTxs

type AddrsPrevTxs struct {
	Addrs         []string
	PrevTxs       []PrevTx
	SenderAccount enum.AccountType
}

AddrsPrevTxs multisig用トランザクション生成時に必要な情報群

type Bitcoin

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

Bitcoin includes Client to call Json-RPC

func NewBitcoin

func NewBitcoin(client *rpcclient.Client, conf *toml.BitcoinConf) (*Bitcoin, error)

NewBitcoin Bitcoinオブジェクトを返す

func (*Bitcoin) AddMultisigAddress

func (b *Bitcoin) AddMultisigAddress(requiredSigs int, addresses []string, accountName string, addressType enum.AddressType) (*AddMultisigAddressResult, error)

AddMultisigAddress マルチシグを Rawトランザクション用に作成する

  • requiredSigs: 取引成立に必要なサイン数
  • addresses: 自分のアドレス+承認者のアドレスxN をいれていく

clientのアドレスは不要。payment/receiptのアドレスはmultisig対応しておくこと

func (*Bitcoin) AmountString

func (b *Bitcoin) AmountString(amt btcutil.Amount) string

AmountString 1.0 BTCといったstringを1.0という単位を除いたstringとして返す

func (*Bitcoin) BackupWallet

func (b *Bitcoin) BackupWallet(fileName string) error

BackupWallet walletファイルをunloadする

Safely copies current wallet file to destination, which can be a directory or a path with filename

func (*Bitcoin) CastStrBitToAmount

func (b *Bitcoin) CastStrBitToAmount(s string) (btcutil.Amount, error)

CastStrBitToAmount string型のBitcoinをAmountに変換する

func (*Bitcoin) CastStrSatoshiToAmount

func (b *Bitcoin) CastStrSatoshiToAmount(s string) (btcutil.Amount, error)

CastStrSatoshiToAmount string型のSatoshiをAmountに変換する

func (*Bitcoin) Client

func (b *Bitcoin) Client() *rpcclient.Client

Client clientオブジェクトを返す

func (*Bitcoin) Close

func (b *Bitcoin) Close()

Close コネクションを切断する

func (*Bitcoin) CoinType

func (b *Bitcoin) CoinType() enum.CoinType

CoinType Bitcoinの種別(btc, bch)を返す

func (*Bitcoin) ConfirmationBlock

func (b *Bitcoin) ConfirmationBlock() int

ConfirmationBlock Confirmationに必要なブロック数を返す

func (*Bitcoin) CreateNewAddress

func (b *Bitcoin) CreateNewAddress(accountName string) (btcutil.Address, error)

CreateNewAddress アカウント名から新しいアドレスを生成する 常に新しいアドレスが生成される これによって作成されたアカウントはbitcoin core側のwalletで管理される TODO:おそらく本番では使わない

func (*Bitcoin) CreateRawTransaction

func (b *Bitcoin) CreateRawTransaction(sendAddr string, amount btcutil.Amount, inputs []btcjson.TransactionInput) (*wire.MsgTx, error)

CreateRawTransaction Rawトランザクションを作成する

=> watch only wallet(online)で利用されることを想定

こちらは多対1用の送金、つまり入金時、集約用アドレスに一括して送信するケースで利用することを想定 [Noted] 手数料を考慮せず、全額送金しようとすると、SendRawTransaction()で、`min relay fee not met`エラーが発生する

func (*Bitcoin) CreateRawTransactionWithOutput

func (b *Bitcoin) CreateRawTransactionWithOutput(inputs []btcjson.TransactionInput, outputs map[btcutil.Address]btcutil.Amount) (*wire.MsgTx, error)

CreateRawTransactionWithOutput 出金時に1対多で送信する場合に利用するトランザクションを作成する

func (*Bitcoin) CreateWallet

func (b *Bitcoin) CreateWallet(fileName string, disablePrivKey bool) error

CreateWallet Creates and loads a new wallet

func (*Bitcoin) DecodeAddress

func (b *Bitcoin) DecodeAddress(addr string) (btcutil.Address, error)

DecodeAddress string型のアドレスをDecodeしてAddress型に変換する

func (*Bitcoin) DecodeRawTransaction

func (b *Bitcoin) DecodeRawTransaction(hexTx string) (*btcjson.TxRawResult, error)

DecodeRawTransaction Hex stringをデコードして、Rawのトランザクションデータに変換する

func (*Bitcoin) DumpWallet

func (b *Bitcoin) DumpWallet(fileName string) error

DumpWallet walletを指定したファイル名でdumpする (これをすることでkeyの存在しないwalletが作られるはず)

fileNameは絶対パス
This does not allow overwriting existing files.

func (*Bitcoin) EncryptWallet

func (b *Bitcoin) EncryptWallet(passphrase string) error

EncryptWallet Walletの初回パスフレーズを設定 0.16.2の場合、`encryptwallet`というmethod名になっている。これは古いのかも

func (*Bitcoin) EstimateSmartFee

func (b *Bitcoin) EstimateSmartFee() (float64, error)

EstimateSmartFee bitcoin coreの`estimatesmartfee`APIをcallする 戻り値はBTC/kB(float64)

func (*Bitcoin) FeeRangeMax

func (b *Bitcoin) FeeRangeMax() float64

FeeRangeMax feeの調整倍率の最大値を返す

func (*Bitcoin) FeeRangeMin

func (b *Bitcoin) FeeRangeMin() float64

FeeRangeMin feeの調整倍率の最小値を返す

func (*Bitcoin) FloatBitToAmount

func (b *Bitcoin) FloatBitToAmount(f float64) (btcutil.Amount, error)

FloatBitToAmount BTC(float64)をSatoshi(Amount)に変換する e.g. 0.54 to 54000000

func (*Bitcoin) FundRawTransaction

func (b *Bitcoin) FundRawTransaction(hex string) (*FundRawTransactionResult, error)

FundRawTransaction 送信したい金額に応じて、自動的にutxoを算出してくれる 未使用のため、コメントアウトしておいてもいいかも

func (*Bitcoin) GetAccount

func (b *Bitcoin) GetAccount(addr string) (string, error)

GetAccount 渡されたアドレスから該当するアカウント名を取得する

func (*Bitcoin) GetAccountAddress

func (b *Bitcoin) GetAccountAddress(accountName string) (btcutil.Address, error)

GetAccountAddress アカウントに紐づくアドレスを返す Deprecated, will be removed in V0.18.

func (*Bitcoin) GetAddressInfo

func (b *Bitcoin) GetAddressInfo(addr string) (*GetAddressInfoResult, error)

GetAddressInfo getaddressinfo RPC をcallする version0.18より、getaccountは呼び出せなくなるので、こちらをcallすること 従来のvalidateaddressより取得していたaddressの詳細情報もこちらから取得可能

func (*Bitcoin) GetAddressesByAccount

func (b *Bitcoin) GetAddressesByAccount(accountName string) ([]btcutil.Address, error)

GetAddressesByAccount アカウント名から紐づくすべてのアドレスを取得する

func (*Bitcoin) GetAddressesByLabel

func (b *Bitcoin) GetAddressesByLabel(labelName string) ([]btcutil.Address, error)

GetAddressesByLabel 指定したラベルに紐づくaddressをすべて返す

func (*Bitcoin) GetBalanceByAccount

func (b *Bitcoin) GetBalanceByAccount(accountName string) (btcutil.Amount, error)

GetBalanceByAccount アカウントに対してのBalanceを取得する

func (*Bitcoin) GetBlockCount

func (b *Bitcoin) GetBlockCount() (int64, error)

GetBlockCount Blockのカウントを返す

e.g. 1383526

func (*Bitcoin) GetChainConf

func (b *Bitcoin) GetChainConf() *chaincfg.Params

GetChainConf 接続先であるMainNet/TestNetに応じて必要なconfを返す

func (*Bitcoin) GetFee

func (b *Bitcoin) GetFee(tx *wire.MsgTx, adjustmentFee float64) (btcutil.Amount, error)

GetFee 手数料を総合的に判断し取得する

func (*Bitcoin) GetNetworkInfo

func (b *Bitcoin) GetNetworkInfo() (*GetNetworkInfoResult, error)

GetNetworkInfo getnetworkinfo RPC をcallする

func (*Bitcoin) GetRawTransactionByHex

func (b *Bitcoin) GetRawTransactionByHex(strHashTx string) (*btcutil.Tx, error)

GetRawTransactionByHex Hexからトランザクションを取得する

func (*Bitcoin) GetReceivedByAccountAndMinConf

func (b *Bitcoin) GetReceivedByAccountAndMinConf(accountName string, minConf int) (btcutil.Amount, error)

GetReceivedByAccountAndMinConf アカウントに対してのBalanceを取得する

func (*Bitcoin) GetReceivedByLabelAndMinConf

func (b *Bitcoin) GetReceivedByLabelAndMinConf(accountName string, minConf int) (btcutil.Amount, error)

GetReceivedByLabelAndMinConf ラベルに対してのBalanceを取得する

func (*Bitcoin) GetTransactionByTxID

func (b *Bitcoin) GetTransactionByTxID(txID string) (*btcjson.GetTransactionResult, error)

GetTransactionByTxID txIDからトランザクション詳細を取得する

func (*Bitcoin) GetTransactionFee

func (b *Bitcoin) GetTransactionFee(tx *wire.MsgTx) (btcutil.Amount, error)

GetTransactionFee トランザクションサイズからfeeを算出する

func (*Bitcoin) GetTxOutByTxID

func (b *Bitcoin) GetTxOutByTxID(txID string, index uint32) (*btcjson.GetTxOutResult, error)

GetTxOutByTxID TxOutを指定したトランザクションIDから取得する

func (*Bitcoin) ImportAddress

func (b *Bitcoin) ImportAddress(pubkey string) error

ImportAddress アドレスをwalletにimportする

func (*Bitcoin) ImportAddressWithLabel

func (b *Bitcoin) ImportAddressWithLabel(address, label string, rescan bool) error

ImportAddressWithLabel address, label, rescanをパラメータとしaddressをwalletにimportする

func (*Bitcoin) ImportAddressWithoutReScan

func (b *Bitcoin) ImportAddressWithoutReScan(pubkey string) error

ImportAddressWithoutReScan Rescanせずにアドレスをwalletにimportする

func (*Bitcoin) ImportPrivKey

func (b *Bitcoin) ImportPrivKey(privKeyWIF *btcutil.WIF) error

ImportPrivKey WIFをwalletに登録する

func (*Bitcoin) ImportPrivKeyLabel

func (b *Bitcoin) ImportPrivKeyLabel(privKeyWIF *btcutil.WIF, label string) error

ImportPrivKeyLabel WIFをwalletに登録する、label付き

func (*Bitcoin) ImportPrivKeyWithoutReScan

func (b *Bitcoin) ImportPrivKeyWithoutReScan(privKeyWIF *btcutil.WIF, label string) error

ImportPrivKeyWithoutReScan WIFをwalletに登録する、rescanはしない

func (*Bitcoin) ImportWallet

func (b *Bitcoin) ImportWallet(fileName string) error

ImportWallet walletファイルをimportする

func (*Bitcoin) ListAccounts

func (b *Bitcoin) ListAccounts() (map[string]btcutil.Amount, error)

ListAccounts これは単純にアカウントの資産一覧が表示されるだけ

func (*Bitcoin) ListUnspent

func (b *Bitcoin) ListUnspent() ([]ListUnspentResult, error)

ListUnspent listunspentを呼び出す

func (*Bitcoin) ListUnspentByAccount

func (b *Bitcoin) ListUnspentByAccount(accountType enum.AccountType) ([]ListUnspentResult, []btcutil.Address, error)

ListUnspentByAccount 指定したアカウントのlistunspentを取得する

func (*Bitcoin) LoadWallet

func (b *Bitcoin) LoadWallet(fileName string) error

LoadWallet walletファイルをimportする

Loads a wallet from a wallet file or directory.
Note that all wallet command-line options used when starting bitcoind will be
applied to the new wallet (eg -zapwallettxes, upgradewallet, rescan, etc).
e.g. bitcoin-cli loadwallet "test.dat"

func (*Bitcoin) LockUnspent

func (b *Bitcoin) LockUnspent(tx btcjson.ListUnspentResult) error

LockUnspent 渡されたtxIDをロックする

func (*Bitcoin) Logging

func (b *Bitcoin) Logging() (*LoggingResult, error)

Logging logging RPC をcallする

func (*Bitcoin) SendTransactionByByte

func (b *Bitcoin) SendTransactionByByte(rawTx []byte) (*chainhash.Hash, error)

SendTransactionByByte 外部から渡されたバイト列からRawトランザクションを送信する オンラインで実行される必要がある

func (*Bitcoin) SendTransactionByHex

func (b *Bitcoin) SendTransactionByHex(hex string) (*chainhash.Hash, error)

SendTransactionByHex 外部から渡されたバイト列からRawトランザクションを送信する オンラインで実行される必要があるため、watchOnlyWallet専用

func (*Bitcoin) SetAccount

func (b *Bitcoin) SetAccount(addr, account string) error

SetAccount 既存のimport済のアドレスにアカウント名をセットする

func (*Bitcoin) SetChainConf

func (b *Bitcoin) SetChainConf(conf *chaincfg.Params)

SetChainConf chainConfをセットする

func (*Bitcoin) SetChainConfNet

func (b *Bitcoin) SetChainConfNet(btcNet wire.BitcoinNet)

SetChainConfNet conf.Netをセットする

func (*Bitcoin) SetCoinType

func (b *Bitcoin) SetCoinType(coinType enum.CoinType)

SetCoinType CoinTypeをセットする

func (*Bitcoin) SetLabel

func (b *Bitcoin) SetLabel(addr, label string) error

SetLabel 既存のimport済のアドレスにラベル名をセットする version0.18より、setaccountは呼び出せなくなるので、SetLabel()をcallすること

func (*Bitcoin) SetVersion

func (b *Bitcoin) SetVersion(ver enum.BTCVersion)

SetVersion バージョン情報をセットする

func (*Bitcoin) Sign

func (b *Bitcoin) Sign(tx *wire.MsgTx, strPrivateKey string) (string, error)

Sign 署名を行う without Bitcoin Core [WIP] FIXME: これはColdWallet内で必要となるが、BitcoinCoreの機能が必要ないので、あれば実装しておきたい

func (*Bitcoin) SignRawTransaction

func (b *Bitcoin) SignRawTransaction(tx *wire.MsgTx, prevtxs []PrevTx) (*wire.MsgTx, bool, error)

SignRawTransaction *wire.MsgTxからRawのトランザクションに署名する 入金時のトランザクション(multisigではないトランザクション)用

func (*Bitcoin) SignRawTransactionWithKey

func (b *Bitcoin) SignRawTransactionWithKey(tx *wire.MsgTx, privKeysWIF []string, prevtxs []PrevTx) (*wire.MsgTx, bool, error)

SignRawTransactionWithKey Multisig時、トランザクションへ署名をする Multisigの場合はこちら For above ver17

func (*Bitcoin) ToHex

func (b *Bitcoin) ToHex(tx *wire.MsgTx) (string, error)

ToHex 16進数のstringに変換する

func (*Bitcoin) ToMsgTx

func (b *Bitcoin) ToMsgTx(txHex string) (*wire.MsgTx, error)

ToMsgTx 16進数のstringから、wire.MsgTxに変換する

func (*Bitcoin) UnLoadWallet

func (b *Bitcoin) UnLoadWallet(fileName string) error

UnLoadWallet walletファイルをunloadする

Unloads the wallet referenced by the request endpoint otherwise unloads the wallet specified in the argument.
Specifying the wallet name on a wallet endpoint is invalid.
e.g. bitcoin-cli unloadwallet wallet_name

func (*Bitcoin) UnlockAllUnspentTransaction

func (b *Bitcoin) UnlockAllUnspentTransaction() error

UnlockAllUnspentTransaction Lockされたトランザクションの解除

func (*Bitcoin) ValidateAddress

func (b *Bitcoin) ValidateAddress(addr string) (*btcjson.ValidateAddressWalletResult, error)

ValidateAddress 渡されたアドレスの整合性をチェックする TODO: こちらの機能はCayenne側でも必要だが、Cayenneから直接利用する場合、Bitcoin Coreの機能に依存しているので、煩雑になってしまう

func (*Bitcoin) Version

func (b *Bitcoin) Version() enum.BTCVersion

Version bitcoin coreのバージョンを返す

func (*Bitcoin) WalletLock

func (b *Bitcoin) WalletLock() error

WalletLock walletにロックをかける(walletpassphraseによってロックを解除するまで利用できない)

func (*Bitcoin) WalletPassphrase

func (b *Bitcoin) WalletPassphrase(passphrase string, timeoutSecs int64) error

WalletPassphrase ロックを解除する

func (*Bitcoin) WalletPassphraseChange

func (b *Bitcoin) WalletPassphraseChange(old, new string) error

WalletPassphraseChange パスフレーズを変更する

type EstimateSmartFeeResult

type EstimateSmartFeeResult struct {
	FeeRate float64  `json:"feerate"`
	Errors  []string `json:"errors"`
	Blocks  int64    `json:"blocks"`
}

EstimateSmartFeeResult estimatesmartfeeをcallしたresponseの型

type FeeAdjustmentRate

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

FeeAdjustmentRate 手数料調整のRange

type FundRawTransactionResult

type FundRawTransactionResult struct {
	Hex       string `json:"hex"`
	Fee       int64  `json:"fee"`
	Changepos int64  `json:"changepos"`
}

FundRawTransactionResult fundrawtransactionをcallしたresponseの型

type GetAddressInfoResult

type GetAddressInfoResult struct {
	Address      string `json:"address"`
	ScriptPubKey string `json:"scriptPubKey"`
	Ismine       bool   `json:"ismine"`
	Iswatchonly  bool   `json:"iswatchonly"`
	Isscript     bool   `json:"isscript"`
	Iswitness    bool   `json:"iswitness"`
	Script       string `json:"script"`
	Hex          string `json:"hex"`
	Pubkey       string `json:"pubkey"`
	Embedded     struct {
		Isscript       bool   `json:"isscript"`
		Iswitness      bool   `json:"iswitness"`
		WitnessVersion int    `json:"witness_version"`
		WitnessProgram string `json:"witness_program"`
		Pubkey         string `json:"pubkey"`
		Address        string `json:"address"`
		ScriptPubKey   string `json:"scriptPubKey"`
	} `json:"embedded"`
	Label     string  `json:"label"`
	Timestamp int64   `json:"timestamp"`
	Labels    []Label `json:"labels"`
}

GetAddressInfoResult getaddressinfoをcallしたresponseの型

type GetNetworkInfoResult

type GetNetworkInfoResult struct {
	Version         enum.BTCVersion `json:"version"`
	Subversion      string          `json:"subversion"`
	Protocolversion int             `json:"protocolversion"`
	Localservices   string          `json:"localservices"`
	Localrelay      bool            `json:"localrelay"`
	Timeoffset      int             `json:"timeoffset"`
	Networkactive   bool            `json:"networkactive"`
	Connections     int             `json:"connections"`
	Networks        []Network       `json:"networks"`
	Relayfee        float64         `json:"relayfee"`
	Incrementalfee  float64         `json:"incrementalfee"`
	Localaddresses  []string        `json:"localaddresses"`
	Warnings        string          `json:"warnings"`
}

GetNetworkInfoResult getnetworkinfo RPC のレスポンス

type Label

type Label struct {
	Name    string `json:"name"`
	Purpose string `json:"purpose"`
}

Label ラベル

type ListUnspentResult

type ListUnspentResult struct {
	TxID          string  `json:"txid"`
	Vout          uint32  `json:"vout"`
	Address       string  `json:"address"`
	Label         string  `json:"label"` //to account
	ScriptPubKey  string  `json:"scriptPubKey"`
	Amount        float64 `json:"amount"`
	Confirmations int64   `json:"confirmations"`
	RedeemScript  string  `json:"redeemScript"`
	Spendable     bool    `json:"spendable"`
	Solvable      bool    `json:"solvable"` //new
	Safe          bool    `json:"safe"`     //new
}

ListUnspentResult listunspentの戻り値

type LoadWalletResult

type LoadWalletResult struct {
	WalletName string `json:"name"`
	Warning    string `json:"warning"`
}

LoadWalletResult loadwallet/createwallet RPCのレスポンス

type LoggingResult

type LoggingResult struct {
	Net         int64 `json:"net"`
	Tor         int64 `json:"tor"`
	Mempool     int64 `json:"mempool"`
	HTTP        int64 `json:"http"`
	Bench       int64 `json:"bench"`
	Zmq         int64 `json:"zmq"`
	DB          int64 `json:"db"`
	RPC         int64 `json:"rpc"`
	EstimateFee int64 `json:"estimatefee"`
	Addrman     int64 `json:"addrman"`
	SelectCoins int64 `json:"selectcoins"`
	ReIndex     int64 `json:"reindex"`
	CmpctBlock  int64 `json:"cmpctblock"`
	Rand        int64 `json:"rand"`
	Prune       int64 `json:"prune"`
	Proxy       int64 `json:"proxy"`
	MempoolRej  int64 `json:"mempoolrej"`
	LibEvent    int64 `json:"libevent"`
	CoinDB      int64 `json:"coindb"`
	Qt          int64 `json:"qt"`
	LevelDB     int64 `json:"leveldb"`
}

LoggingResult logging RPC のレスポンス

type Network

type Network struct {
	Name                      string `json:"name"`
	Limited                   bool   `json:"limited"`
	Reachable                 bool   `json:"reachable"`
	Proxy                     string `json:"proxy"`
	ProxyRandomizeCredentials bool   `json:"proxy_randomize_credentials"`
}

Network ネットワーク情報

type PrevTx

type PrevTx struct {
	Txid         string  `json:"txid"`
	Vout         uint32  `json:"vout"`
	ScriptPubKey string  `json:"scriptPubKey"`
	RedeemScript string  `json:"redeemScript"`
	Amount       float64 `json:"amount"`
}

PrevTx multisig時のsignrawtransactionで必要なパラメータ

type Purpose

type Purpose struct {
	Purpose string `json:"purpose"`
}

Purpose 目的

type SignRawTransactionError

type SignRawTransactionError struct {
	Txid      string `json:"txid"`
	Vout      int64  `json:"vout"`
	ScriptSig string `json:"scriptSig"`
	Sequence  int64  `json:"sequence"`
	Error     string `json:"error"`
}

SignRawTransactionError SignRawTransactionResult内のerrorオブジェクト

type SignRawTransactionResult

type SignRawTransactionResult struct {
	Hex      string                    `json:"hex"`
	Complete bool                      `json:"complete"`
	Errors   []SignRawTransactionError `json:"errors"`
}

SignRawTransactionResult signrawtransactionwithwalletをcallしたresponseの型

type WalletResult

type WalletResult struct {
	FileName string `json:"filename"`
}

WalletResult dumpwallet/dumpwallet RPC のレスポンス

Jump to

Keyboard shortcuts

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