diff --git a/bchain/coins/bch/bcashparser.go b/bchain/coins/bch/bcashparser.go index f940c8081a..3a732f85ab 100644 --- a/bchain/coins/bch/bcashparser.go +++ b/bchain/coins/bch/bcashparser.go @@ -12,22 +12,31 @@ import ( "github.com/schancel/cashaddr-converter/address" ) +// AddressFormat type is used to specify different formats of address type AddressFormat = uint8 const ( + // Legacy AddressFormat is the same as Bitcoin Legacy AddressFormat = iota + // CashAddr AddressFormat is new Bitcoin Cash standard CashAddr ) const ( + // MainNetPrefix is CashAddr prefix for mainnet MainNetPrefix = "bitcoincash:" + // TestNetPrefix is CashAddr prefix for testnet TestNetPrefix = "bchtest:" + // RegTestPrefix is CashAddr prefix for regtest RegTestPrefix = "bchreg:" ) var ( + // MainNetParams are parser parameters for mainnet MainNetParams chaincfg.Params + // TestNetParams are parser parameters for testnet TestNetParams chaincfg.Params + // RegtestParams are parser parameters for regtest RegtestParams chaincfg.Params ) @@ -118,17 +127,16 @@ func (p *BCashParser) addressToOutputScript(address string) ([]byte, error) { return nil, err } return script, nil - } else { - da, err := btcutil.DecodeAddress(address, p.Params) - if err != nil { - return nil, err - } - script, err := txscript.PayToAddrScript(da) - if err != nil { - return nil, err - } - return script, nil } + da, err := btcutil.DecodeAddress(address, p.Params) + if err != nil { + return nil, err + } + script, err := txscript.PayToAddrScript(da) + if err != nil { + return nil, err + } + return script, nil } func isCashAddr(addr string) bool { @@ -163,9 +171,8 @@ func (p *BCashParser) outputScriptToAddresses(script []byte) ([]string, bool, er return []string{or}, false, nil } return []string{}, false, nil - } else { - return nil, false, err } + return nil, false, err } // EncodeAddress returns CashAddr address addr := a.EncodeAddress() diff --git a/bchain/coins/dash/dashparser.go b/bchain/coins/dash/dashparser.go index 9d4d4d4f97..57e06f726b 100644 --- a/bchain/coins/dash/dashparser.go +++ b/bchain/coins/dash/dashparser.go @@ -9,14 +9,20 @@ import ( ) const ( + // MainnetMagic is mainnet network constant MainnetMagic wire.BitcoinNet = 0xbd6b0cbf + // TestnetMagic is testnet network constant TestnetMagic wire.BitcoinNet = 0xffcae2ce + // RegtestMagic is regtest network constant RegtestMagic wire.BitcoinNet = 0xdcb7c1fc ) var ( + // MainNetParams are parser parameters for mainnet MainNetParams chaincfg.Params + // TestNetParams are parser parameters for testnet TestNetParams chaincfg.Params + // RegtestParams are parser parameters for regtest RegtestParams chaincfg.Params ) diff --git a/bchain/coins/dash/dashrpc.go b/bchain/coins/dash/dashrpc.go index a2aea6ba16..66629d79cc 100644 --- a/bchain/coins/dash/dashrpc.go +++ b/bchain/coins/dash/dashrpc.go @@ -11,12 +11,12 @@ import ( const firstBlockWithSpecialTransactions = 1028160 -// DashRPC is an interface to JSON-RPC bitcoind service. +// DashRPC is an interface to JSON-RPC bitcoind service type DashRPC struct { *btc.BitcoinRPC } -// NewDashRPC returns new DashRPC instance. +// NewDashRPC returns new DashRPC instance func NewDashRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) { b, err := btc.NewBitcoinRPC(config, pushHandler) if err != nil { @@ -58,7 +58,7 @@ func (b *DashRPC) Initialize() error { return nil } -// GetBlock returns block with given hash. +// GetBlock returns block with given hash func (b *DashRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) { if hash == "" && height < firstBlockWithSpecialTransactions { return b.BitcoinRPC.GetBlock(hash, height) @@ -108,6 +108,6 @@ func (b *DashRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) { // GetTransactionForMempool returns a transaction by the transaction ID. // It could be optimized for mempool, i.e. without block time and confirmations -func (z *DashRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) { - return z.GetTransaction(txid) +func (b *DashRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) { + return b.GetTransaction(txid) } diff --git a/bchain/coins/zec/zcashparser.go b/bchain/coins/zec/zcashparser.go index 1a1ed72bb1..3c0e58176f 100644 --- a/bchain/coins/zec/zcashparser.go +++ b/bchain/coins/zec/zcashparser.go @@ -9,14 +9,20 @@ import ( ) const ( + // MainnetMagic is mainnet network constant MainnetMagic wire.BitcoinNet = 0x6427e924 + // TestnetMagic is testnet network constant TestnetMagic wire.BitcoinNet = 0xbff91afa + // RegtestMagic is regtest network constant RegtestMagic wire.BitcoinNet = 0x5f3fe8aa ) var ( + // MainNetParams are parser parameters for mainnet MainNetParams chaincfg.Params + // TestNetParams are parser parameters for testnet TestNetParams chaincfg.Params + // RegtestParams are parser parameters for regtest RegtestParams chaincfg.Params ) diff --git a/bchain/coins/zec/zcashrpc.go b/bchain/coins/zec/zcashrpc.go index fa956f1e75..3ecffea3c4 100644 --- a/bchain/coins/zec/zcashrpc.go +++ b/bchain/coins/zec/zcashrpc.go @@ -9,10 +9,12 @@ import ( "github.com/juju/errors" ) +// ZCashRPC is an interface to JSON-RPC bitcoind service type ZCashRPC struct { *btc.BitcoinRPC } +// NewZCashRPC returns new ZCashRPC instance func NewZCashRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) { b, err := btc.NewBitcoinRPC(config, pushHandler) if err != nil { @@ -26,7 +28,7 @@ func NewZCashRPC(config json.RawMessage, pushHandler func(bchain.NotificationTyp return z, nil } -// Initialize initializes ZCashRPC instance. +// Initialize initializes ZCashRPC instance func (z *ZCashRPC) Initialize() error { chainName, err := z.GetChainInfoAndInitializeMempool(z) if err != nil {