change energi signatures
parent
0447b72add
commit
9ca0eb348c
|
@ -70,7 +70,7 @@ func init() {
|
|||
BlockChainFactories["Ethereum Classic"] = eth.NewEthereumRPC
|
||||
BlockChainFactories["Ethereum Testnet Ropsten"] = eth.NewEthereumRPC
|
||||
BlockChainFactories["Ethereum Testnet Goerli"] = eth.NewEthereumRPC
|
||||
BlockChainFactories["Energi"] = energi.NewEthereumRPC
|
||||
BlockChainFactories["Energi"] = energi.NewEnergiRPC
|
||||
BlockChainFactories["Bcash"] = bch.NewBCashRPC
|
||||
BlockChainFactories["Bcash Testnet"] = bch.NewBCashRPC
|
||||
BlockChainFactories["Bgold"] = btg.NewBGoldRPC
|
||||
|
|
|
@ -91,7 +91,7 @@ func erc20GetTransfersFromTx(tx *rpcTransaction) ([]bchain.Erc20Transfer, error)
|
|||
return r, nil
|
||||
}
|
||||
|
||||
func (b *EthereumRPC) ethCall(data, to string) (string, error) {
|
||||
func (b *EnergiRPC) ethCall(data, to string) (string, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
|
||||
defer cancel()
|
||||
var r string
|
||||
|
@ -159,7 +159,7 @@ func parseErc20StringProperty(contractDesc bchain.AddressDescriptor, data string
|
|||
}
|
||||
|
||||
// EthereumTypeGetErc20ContractInfo returns information about ERC20 contract
|
||||
func (b *EthereumRPC) EthereumTypeGetErc20ContractInfo(contractDesc bchain.AddressDescriptor) (*bchain.Erc20Contract, error) {
|
||||
func (b *EnergiRPC) EthereumTypeGetErc20ContractInfo(contractDesc bchain.AddressDescriptor) (*bchain.Erc20Contract, error) {
|
||||
cds := string(contractDesc)
|
||||
cachedContractsMux.Lock()
|
||||
contract, found := cachedContracts[cds]
|
||||
|
@ -211,7 +211,7 @@ func (b *EthereumRPC) EthereumTypeGetErc20ContractInfo(contractDesc bchain.Addre
|
|||
}
|
||||
|
||||
// EthereumTypeGetErc20ContractBalance returns balance of ERC20 contract for given address
|
||||
func (b *EthereumRPC) EthereumTypeGetErc20ContractBalance(addrDesc, contractDesc bchain.AddressDescriptor) (*big.Int, error) {
|
||||
func (b *EnergiRPC) EthereumTypeGetErc20ContractBalance(addrDesc, contractDesc bchain.AddressDescriptor) (*big.Int, error) {
|
||||
addr := EIP55Address(addrDesc)
|
||||
contract := EIP55Address(contractDesc)
|
||||
req := erc20BalanceOf + "0000000000000000000000000000000000000000000000000000000000000000"[len(addr)-2:] + addr[2:]
|
||||
|
|
|
@ -162,7 +162,7 @@ func TestErc20_parseErc20StringProperty(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestErc20_erc20GetTransfersFromTx(t *testing.T) {
|
||||
p := NewEthereumParser(1)
|
||||
p := NewEnergiParser(1)
|
||||
b := dbtestdata.GetTestEthereumTypeBlock1(p)
|
||||
bn, _ := new(big.Int).SetString("21e19e0c9bab2400000", 16)
|
||||
tests := []struct {
|
||||
|
|
|
@ -18,14 +18,14 @@ const EthereumTypeAddressDescriptorLen = 20
|
|||
// EtherAmountDecimalPoint defines number of decimal points in Ether amounts
|
||||
const EtherAmountDecimalPoint = 18
|
||||
|
||||
// EthereumParser handle
|
||||
type EthereumParser struct {
|
||||
// EnergiParser handle
|
||||
type EnergiParser struct {
|
||||
*bchain.BaseParser
|
||||
}
|
||||
|
||||
// NewEthereumParser returns new EthereumParser instance
|
||||
func NewEthereumParser(b int) *EthereumParser {
|
||||
return &EthereumParser{&bchain.BaseParser{
|
||||
// NewEnergiParser returns new EnergiParser instance
|
||||
func NewEnergiParser(b int) *EnergiParser {
|
||||
return &EnergiParser{&bchain.BaseParser{
|
||||
BlockAddressesToKeep: b,
|
||||
AmountDecimalPoint: EtherAmountDecimalPoint,
|
||||
}}
|
||||
|
@ -104,7 +104,7 @@ type header struct {
|
|||
Hash hash `json:"hash"`
|
||||
}
|
||||
|
||||
func (p *EthereumParser) ethTxToTx(tx *rpcTransaction, receipt *rpcReceipt, blocktime int64, confirmations uint32, fixEIP55 bool) (*bchain.Tx, error) {
|
||||
func (p *EnergiParser) ethTxToTx(tx *rpcTransaction, receipt *rpcReceipt, blocktime int64, confirmations uint32, fixEIP55 bool) (*bchain.Tx, error) {
|
||||
txid := tx.Hash
|
||||
var (
|
||||
fa, ta []string
|
||||
|
@ -169,7 +169,7 @@ func (p *EthereumParser) ethTxToTx(tx *rpcTransaction, receipt *rpcReceipt, bloc
|
|||
}
|
||||
|
||||
// GetAddrDescFromVout returns internal address representation of given transaction output
|
||||
func (p *EthereumParser) GetAddrDescFromVout(output *bchain.Vout) (bchain.AddressDescriptor, error) {
|
||||
func (p *EnergiParser) GetAddrDescFromVout(output *bchain.Vout) (bchain.AddressDescriptor, error) {
|
||||
if len(output.ScriptPubKey.Addresses) != 1 {
|
||||
return nil, bchain.ErrAddressMissing
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ func has0xPrefix(s string) bool {
|
|||
}
|
||||
|
||||
// GetAddrDescFromAddress returns internal address representation of given address
|
||||
func (p *EthereumParser) GetAddrDescFromAddress(address string) (bchain.AddressDescriptor, error) {
|
||||
func (p *EnergiParser) GetAddrDescFromAddress(address string) (bchain.AddressDescriptor, error) {
|
||||
// github.com/ethereum/go-ethereum/common.HexToAddress does not handle address errors, using own decoding
|
||||
if has0xPrefix(address) {
|
||||
address = address[2:]
|
||||
|
@ -230,12 +230,12 @@ func EIP55AddressFromAddress(address string) string {
|
|||
}
|
||||
|
||||
// GetAddressesFromAddrDesc returns addresses for given address descriptor with flag if the addresses are searchable
|
||||
func (p *EthereumParser) GetAddressesFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]string, bool, error) {
|
||||
func (p *EnergiParser) GetAddressesFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]string, bool, error) {
|
||||
return []string{EIP55Address(addrDesc)}, true, nil
|
||||
}
|
||||
|
||||
// GetScriptFromAddrDesc returns output script for given address descriptor
|
||||
func (p *EthereumParser) GetScriptFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]byte, error) {
|
||||
func (p *EnergiParser) GetScriptFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]byte, error) {
|
||||
return addrDesc, nil
|
||||
}
|
||||
|
||||
|
@ -262,7 +262,7 @@ func hexEncodeBig(b []byte) string {
|
|||
}
|
||||
|
||||
// PackTx packs transaction to byte array
|
||||
func (p *EthereumParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) ([]byte, error) {
|
||||
func (p *EnergiParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) ([]byte, error) {
|
||||
var err error
|
||||
var n uint64
|
||||
r, ok := tx.CoinSpecificData.(completeTransaction)
|
||||
|
@ -358,7 +358,7 @@ func (p *EthereumParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) (
|
|||
}
|
||||
|
||||
// UnpackTx unpacks transaction from byte array
|
||||
func (p *EthereumParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
|
||||
func (p *EnergiParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
|
||||
var pt ProtoCompleteTransaction
|
||||
err := proto.Unmarshal(buf, &pt)
|
||||
if err != nil {
|
||||
|
@ -412,12 +412,12 @@ func (p *EthereumParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
|
|||
}
|
||||
|
||||
// PackedTxidLen returns length in bytes of packed txid
|
||||
func (p *EthereumParser) PackedTxidLen() int {
|
||||
func (p *EnergiParser) PackedTxidLen() int {
|
||||
return 32
|
||||
}
|
||||
|
||||
// PackTxid packs txid to byte array
|
||||
func (p *EthereumParser) PackTxid(txid string) ([]byte, error) {
|
||||
func (p *EnergiParser) PackTxid(txid string) ([]byte, error) {
|
||||
if has0xPrefix(txid) {
|
||||
txid = txid[2:]
|
||||
}
|
||||
|
@ -425,12 +425,12 @@ func (p *EthereumParser) PackTxid(txid string) ([]byte, error) {
|
|||
}
|
||||
|
||||
// UnpackTxid unpacks byte array to txid
|
||||
func (p *EthereumParser) UnpackTxid(buf []byte) (string, error) {
|
||||
func (p *EnergiParser) UnpackTxid(buf []byte) (string, error) {
|
||||
return hexutil.Encode(buf), nil
|
||||
}
|
||||
|
||||
// PackBlockHash packs block hash to byte array
|
||||
func (p *EthereumParser) PackBlockHash(hash string) ([]byte, error) {
|
||||
func (p *EnergiParser) PackBlockHash(hash string) ([]byte, error) {
|
||||
if has0xPrefix(hash) {
|
||||
hash = hash[2:]
|
||||
}
|
||||
|
@ -438,12 +438,12 @@ func (p *EthereumParser) PackBlockHash(hash string) ([]byte, error) {
|
|||
}
|
||||
|
||||
// UnpackBlockHash unpacks byte array to block hash
|
||||
func (p *EthereumParser) UnpackBlockHash(buf []byte) (string, error) {
|
||||
func (p *EnergiParser) UnpackBlockHash(buf []byte) (string, error) {
|
||||
return hexutil.Encode(buf), nil
|
||||
}
|
||||
|
||||
// GetChainType returns EthereumType
|
||||
func (p *EthereumParser) GetChainType() bchain.ChainType {
|
||||
func (p *EnergiParser) GetChainType() bchain.ChainType {
|
||||
return bchain.ChainEthereumType
|
||||
}
|
||||
|
||||
|
@ -463,7 +463,7 @@ func GetHeightFromTx(tx *bchain.Tx) (uint32, error) {
|
|||
}
|
||||
|
||||
// EthereumTypeGetErc20FromTx returns Erc20 data from bchain.Tx
|
||||
func (p *EthereumParser) EthereumTypeGetErc20FromTx(tx *bchain.Tx) ([]bchain.Erc20Transfer, error) {
|
||||
func (p *EnergiParser) EthereumTypeGetErc20FromTx(tx *bchain.Tx) ([]bchain.Erc20Transfer, error) {
|
||||
var r []bchain.Erc20Transfer
|
||||
var err error
|
||||
csd, ok := tx.CoinSpecificData.(completeTransaction)
|
||||
|
|
|
@ -54,7 +54,7 @@ func TestEthParser_GetAddrDescFromAddress(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
p := NewEthereumParser(1)
|
||||
p := NewEnergiParser(1)
|
||||
got, err := p.GetAddrDescFromAddress(tt.args.address)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("EthParser.GetAddrDescFromAddress() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
@ -235,7 +235,7 @@ func init() {
|
|||
|
||||
}
|
||||
|
||||
func TestEthereumParser_PackTx(t *testing.T) {
|
||||
func TestEnergiParser_PackTx(t *testing.T) {
|
||||
type args struct {
|
||||
tx *bchain.Tx
|
||||
height uint32
|
||||
|
@ -243,7 +243,7 @@ func TestEthereumParser_PackTx(t *testing.T) {
|
|||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
p *EthereumParser
|
||||
p *EnergiParser
|
||||
args args
|
||||
want string
|
||||
wantErr bool
|
||||
|
@ -285,29 +285,29 @@ func TestEthereumParser_PackTx(t *testing.T) {
|
|||
want: dbtestdata.EthTx1NoStatusPacked,
|
||||
},
|
||||
}
|
||||
p := NewEthereumParser(1)
|
||||
p := NewEnergiParser(1)
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := p.PackTx(tt.args.tx, tt.args.height, tt.args.blockTime)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("EthereumParser.PackTx() error = %v, wantErr %v", err, tt.wantErr)
|
||||
t.Errorf("EnergiParser.PackTx() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
h := hex.EncodeToString(got)
|
||||
if !reflect.DeepEqual(h, tt.want) {
|
||||
t.Errorf("EthereumParser.PackTx() = %v, want %v", h, tt.want)
|
||||
t.Errorf("EnergiParser.PackTx() = %v, want %v", h, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEthereumParser_UnpackTx(t *testing.T) {
|
||||
func TestEnergiParser_UnpackTx(t *testing.T) {
|
||||
type args struct {
|
||||
hex string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
p *EthereumParser
|
||||
p *EnergiParser
|
||||
args args
|
||||
want *bchain.Tx
|
||||
want1 uint32
|
||||
|
@ -338,7 +338,7 @@ func TestEthereumParser_UnpackTx(t *testing.T) {
|
|||
want1: 4321000,
|
||||
},
|
||||
}
|
||||
p := NewEthereumParser(1)
|
||||
p := NewEnergiParser(1)
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
b, err := hex.DecodeString(tt.args.hex)
|
||||
|
@ -347,7 +347,7 @@ func TestEthereumParser_UnpackTx(t *testing.T) {
|
|||
}
|
||||
got, got1, err := p.UnpackTx(b)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("EthereumParser.UnpackTx() error = %v, wantErr %v", err, tt.wantErr)
|
||||
t.Errorf("EnergiParser.UnpackTx() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
// DeepEqual has problems with pointers in completeTransaction
|
||||
|
@ -359,22 +359,22 @@ func TestEthereumParser_UnpackTx(t *testing.T) {
|
|||
wc.CoinSpecificData = nil
|
||||
if fmt.Sprint(gc) != fmt.Sprint(wc) {
|
||||
// if !reflect.DeepEqual(gc, wc) {
|
||||
t.Errorf("EthereumParser.UnpackTx() gc got = %+v, want %+v", gc, wc)
|
||||
t.Errorf("EnergiParser.UnpackTx() gc got = %+v, want %+v", gc, wc)
|
||||
}
|
||||
if !reflect.DeepEqual(gs.Tx, ws.Tx) {
|
||||
t.Errorf("EthereumParser.UnpackTx() gs.Tx got = %+v, want %+v", gs.Tx, ws.Tx)
|
||||
t.Errorf("EnergiParser.UnpackTx() gs.Tx got = %+v, want %+v", gs.Tx, ws.Tx)
|
||||
}
|
||||
if !reflect.DeepEqual(gs.Receipt, ws.Receipt) {
|
||||
t.Errorf("EthereumParser.UnpackTx() gs.Receipt got = %+v, want %+v", gs.Receipt, ws.Receipt)
|
||||
t.Errorf("EnergiParser.UnpackTx() gs.Receipt got = %+v, want %+v", gs.Receipt, ws.Receipt)
|
||||
}
|
||||
if got1 != tt.want1 {
|
||||
t.Errorf("EthereumParser.UnpackTx() got1 = %v, want %v", got1, tt.want1)
|
||||
t.Errorf("EnergiParser.UnpackTx() got1 = %v, want %v", got1, tt.want1)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEthereumParser_GetEthereumTxData(t *testing.T) {
|
||||
func TestEnergiParser_GetEthereumTxData(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
tx *bchain.Tx
|
||||
|
@ -395,7 +395,7 @@ func TestEthereumParser_GetEthereumTxData(t *testing.T) {
|
|||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := GetEthereumTxData(tt.tx)
|
||||
if got.Data != tt.want {
|
||||
t.Errorf("EthereumParser.GetEthereumTxData() = %v, want %v", got.Data, tt.want)
|
||||
t.Errorf("EnergiParser.GetEthereumTxData() = %v, want %v", got.Data, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -41,13 +41,13 @@ type Configuration struct {
|
|||
QueryBackendOnMempoolResync bool `json:"queryBackendOnMempoolResync"`
|
||||
}
|
||||
|
||||
// EthereumRPC is an interface to JSON-RPC eth service.
|
||||
type EthereumRPC struct {
|
||||
// EnergiRPC is an interface to JSON-RPC eth service.
|
||||
type EnergiRPC struct {
|
||||
*bchain.BaseChain
|
||||
client *ethclient.Client
|
||||
rpc *rpc.Client
|
||||
timeout time.Duration
|
||||
Parser *EthereumParser
|
||||
Parser *EnergiParser
|
||||
Mempool *bchain.MempoolEthereumType
|
||||
mempoolInitialized bool
|
||||
bestHeaderLock sync.Mutex
|
||||
|
@ -60,8 +60,8 @@ type EthereumRPC struct {
|
|||
ChainConfig *Configuration
|
||||
}
|
||||
|
||||
// NewEthereumRPC returns new EthRPC instance.
|
||||
func NewEthereumRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) {
|
||||
// NewEnergiRPC returns new EthRPC instance.
|
||||
func NewEnergiRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) {
|
||||
var err error
|
||||
var c Configuration
|
||||
err = json.Unmarshal(config, &c)
|
||||
|
@ -78,7 +78,7 @@ func NewEthereumRPC(config json.RawMessage, pushHandler func(bchain.Notification
|
|||
return nil, err
|
||||
}
|
||||
|
||||
s := &EthereumRPC{
|
||||
s := &EnergiRPC{
|
||||
BaseChain: &bchain.BaseChain{},
|
||||
client: ec,
|
||||
rpc: rc,
|
||||
|
@ -86,7 +86,7 @@ func NewEthereumRPC(config json.RawMessage, pushHandler func(bchain.Notification
|
|||
}
|
||||
|
||||
// always create parser
|
||||
s.Parser = NewEthereumParser(c.BlockAddressesToKeep)
|
||||
s.Parser = NewEnergiParser(c.BlockAddressesToKeep)
|
||||
s.timeout = time.Duration(c.RPCTimeout) * time.Second
|
||||
|
||||
// new blocks notifications handling
|
||||
|
@ -140,7 +140,7 @@ func openRPC(url string) (*rpc.Client, *ethclient.Client, error) {
|
|||
}
|
||||
|
||||
// Initialize initializes ethereum rpc interface
|
||||
func (b *EthereumRPC) Initialize() error {
|
||||
func (b *EnergiRPC) Initialize() error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
|
||||
defer cancel()
|
||||
|
||||
|
@ -168,7 +168,7 @@ func (b *EthereumRPC) Initialize() error {
|
|||
}
|
||||
|
||||
// CreateMempool creates mempool if not already created, however does not initialize it
|
||||
func (b *EthereumRPC) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, error) {
|
||||
func (b *EnergiRPC) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, error) {
|
||||
if b.Mempool == nil {
|
||||
b.Mempool = bchain.NewMempoolEthereumType(chain, b.ChainConfig.MempoolTxTimeoutHours, b.ChainConfig.QueryBackendOnMempoolResync)
|
||||
glog.Info("mempool created, MempoolTxTimeoutHours=", b.ChainConfig.MempoolTxTimeoutHours, ", QueryBackendOnMempoolResync=", b.ChainConfig.QueryBackendOnMempoolResync)
|
||||
|
@ -177,7 +177,7 @@ func (b *EthereumRPC) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, er
|
|||
}
|
||||
|
||||
// InitializeMempool creates subscriptions to newHeads and newPendingTransactions
|
||||
func (b *EthereumRPC) InitializeMempool(addrDescForOutpoint bchain.AddrDescForOutpointFunc, onNewTxAddr bchain.OnNewTxAddrFunc, onNewTx bchain.OnNewTxFunc) error {
|
||||
func (b *EnergiRPC) InitializeMempool(addrDescForOutpoint bchain.AddrDescForOutpointFunc, onNewTxAddr bchain.OnNewTxAddrFunc, onNewTx bchain.OnNewTxFunc) error {
|
||||
if b.Mempool == nil {
|
||||
return errors.New("Mempool not created")
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ func (b *EthereumRPC) InitializeMempool(addrDescForOutpoint bchain.AddrDescForOu
|
|||
return nil
|
||||
}
|
||||
|
||||
func (b *EthereumRPC) subscribeEvents() error {
|
||||
func (b *EnergiRPC) subscribeEvents() error {
|
||||
// subscriptions
|
||||
if err := b.subscribe(func() (*rpc.ClientSubscription, error) {
|
||||
// invalidate the previous subscription - it is either the first one or there was an error
|
||||
|
@ -241,7 +241,7 @@ func (b *EthereumRPC) subscribeEvents() error {
|
|||
}
|
||||
|
||||
// subscribe subscribes notification and tries to resubscribe in case of error
|
||||
func (b *EthereumRPC) subscribe(f func() (*rpc.ClientSubscription, error)) error {
|
||||
func (b *EnergiRPC) subscribe(f func() (*rpc.ClientSubscription, error)) error {
|
||||
s, err := f()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -280,7 +280,7 @@ func (b *EthereumRPC) subscribe(f func() (*rpc.ClientSubscription, error)) error
|
|||
return nil
|
||||
}
|
||||
|
||||
func (b *EthereumRPC) closeRPC() {
|
||||
func (b *EnergiRPC) closeRPC() {
|
||||
if b.newBlockSubscription != nil {
|
||||
b.newBlockSubscription.Unsubscribe()
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ func (b *EthereumRPC) closeRPC() {
|
|||
}
|
||||
}
|
||||
|
||||
func (b *EthereumRPC) reconnectRPC() error {
|
||||
func (b *EnergiRPC) reconnectRPC() error {
|
||||
glog.Info("Reconnecting RPC")
|
||||
b.closeRPC()
|
||||
rc, ec, err := openRPC(b.ChainConfig.RPCURL)
|
||||
|
@ -305,7 +305,7 @@ func (b *EthereumRPC) reconnectRPC() error {
|
|||
}
|
||||
|
||||
// Shutdown cleans up rpc interface to ethereum
|
||||
func (b *EthereumRPC) Shutdown(ctx context.Context) error {
|
||||
func (b *EnergiRPC) Shutdown(ctx context.Context) error {
|
||||
b.closeRPC()
|
||||
close(b.chanNewBlock)
|
||||
glog.Info("rpc: shutdown")
|
||||
|
@ -313,17 +313,17 @@ func (b *EthereumRPC) Shutdown(ctx context.Context) error {
|
|||
}
|
||||
|
||||
// GetCoinName returns coin name
|
||||
func (b *EthereumRPC) GetCoinName() string {
|
||||
func (b *EnergiRPC) GetCoinName() string {
|
||||
return b.ChainConfig.CoinName
|
||||
}
|
||||
|
||||
// GetSubversion returns empty string, ethereum does not have subversion
|
||||
func (b *EthereumRPC) GetSubversion() string {
|
||||
func (b *EnergiRPC) GetSubversion() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetChainInfo returns information about the connected backend
|
||||
func (b *EthereumRPC) GetChainInfo() (*bchain.ChainInfo, error) {
|
||||
func (b *EnergiRPC) GetChainInfo() (*bchain.ChainInfo, error) {
|
||||
h, err := b.getBestHeader()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -357,7 +357,7 @@ func (b *EthereumRPC) GetChainInfo() (*bchain.ChainInfo, error) {
|
|||
return rv, nil
|
||||
}
|
||||
|
||||
func (b *EthereumRPC) getBestHeader() (*header, error) {
|
||||
func (b *EnergiRPC) getBestHeader() (*header, error) {
|
||||
b.bestHeaderLock.Lock()
|
||||
defer b.bestHeaderLock.Unlock()
|
||||
// if the best header was not updated for 15 minutes, there could be a subscription problem, reconnect RPC
|
||||
|
@ -384,7 +384,7 @@ func (b *EthereumRPC) getBestHeader() (*header, error) {
|
|||
}
|
||||
|
||||
// GetBestBlockHash returns hash of the tip of the best-block-chain
|
||||
func (b *EthereumRPC) GetBestBlockHash() (string, error) {
|
||||
func (b *EnergiRPC) GetBestBlockHash() (string, error) {
|
||||
h, err := b.getBestHeader()
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -393,7 +393,7 @@ func (b *EthereumRPC) GetBestBlockHash() (string, error) {
|
|||
}
|
||||
|
||||
// GetBestBlockHeight returns height of the tip of the best-block-chain
|
||||
func (b *EthereumRPC) GetBestBlockHeight() (uint32, error) {
|
||||
func (b *EnergiRPC) GetBestBlockHeight() (uint32, error) {
|
||||
h, err := b.getBestHeader()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -402,7 +402,7 @@ func (b *EthereumRPC) GetBestBlockHeight() (uint32, error) {
|
|||
}
|
||||
|
||||
// GetBlockHash returns hash of block in best-block-chain at given height
|
||||
func (b *EthereumRPC) GetBlockHash(height uint32) (string, error) {
|
||||
func (b *EnergiRPC) GetBlockHash(height uint32) (string, error) {
|
||||
var n big.Int
|
||||
n.SetUint64(uint64(height))
|
||||
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
|
||||
|
@ -417,7 +417,7 @@ func (b *EthereumRPC) GetBlockHash(height uint32) (string, error) {
|
|||
return string(h.Hash), nil
|
||||
}
|
||||
|
||||
func (b *EthereumRPC) ethHeaderToBlockHeader(h *rpcHeader) (*bchain.BlockHeader, error) {
|
||||
func (b *EnergiRPC) ethHeaderToBlockHeader(h *rpcHeader) (*bchain.BlockHeader, error) {
|
||||
height, err := ethNumber(h.Number)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -445,7 +445,7 @@ func (b *EthereumRPC) ethHeaderToBlockHeader(h *rpcHeader) (*bchain.BlockHeader,
|
|||
}
|
||||
|
||||
// GetBlockHeader returns header of block with given hash
|
||||
func (b *EthereumRPC) GetBlockHeader(hash string) (*bchain.BlockHeader, error) {
|
||||
func (b *EnergiRPC) GetBlockHeader(hash string) (*bchain.BlockHeader, error) {
|
||||
raw, err := b.getBlockRaw(hash, 0, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -457,7 +457,7 @@ func (b *EthereumRPC) GetBlockHeader(hash string) (*bchain.BlockHeader, error) {
|
|||
return b.ethHeaderToBlockHeader(&h)
|
||||
}
|
||||
|
||||
func (b *EthereumRPC) computeConfirmations(n uint64) (uint32, error) {
|
||||
func (b *EnergiRPC) computeConfirmations(n uint64) (uint32, error) {
|
||||
bh, err := b.getBestHeader()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -467,7 +467,7 @@ func (b *EthereumRPC) computeConfirmations(n uint64) (uint32, error) {
|
|||
return uint32(bn - n + 1), nil
|
||||
}
|
||||
|
||||
func (b *EthereumRPC) getBlockRaw(hash string, height uint32, fullTxs bool) (json.RawMessage, error) {
|
||||
func (b *EnergiRPC) getBlockRaw(hash string, height uint32, fullTxs bool) (json.RawMessage, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
|
||||
defer cancel()
|
||||
var raw json.RawMessage
|
||||
|
@ -489,7 +489,7 @@ func (b *EthereumRPC) getBlockRaw(hash string, height uint32, fullTxs bool) (jso
|
|||
return raw, nil
|
||||
}
|
||||
|
||||
func (b *EthereumRPC) getERC20EventsForBlock(blockNumber string) (map[string][]*rpcLog, error) {
|
||||
func (b *EnergiRPC) getERC20EventsForBlock(blockNumber string) (map[string][]*rpcLog, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
|
||||
defer cancel()
|
||||
var logs []rpcLogWithTxHash
|
||||
|
@ -510,7 +510,7 @@ func (b *EthereumRPC) getERC20EventsForBlock(blockNumber string) (map[string][]*
|
|||
}
|
||||
|
||||
// GetBlock returns block with given hash or height, hash has precedence if both passed
|
||||
func (b *EthereumRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) {
|
||||
func (b *EnergiRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) {
|
||||
raw, err := b.getBlockRaw(hash, height, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -552,7 +552,7 @@ func (b *EthereumRPC) GetBlock(hash string, height uint32) (*bchain.Block, error
|
|||
}
|
||||
|
||||
// GetBlockInfo returns extended header (more info than in bchain.BlockHeader) with a list of txids
|
||||
func (b *EthereumRPC) GetBlockInfo(hash string) (*bchain.BlockInfo, error) {
|
||||
func (b *EnergiRPC) GetBlockInfo(hash string) (*bchain.BlockInfo, error) {
|
||||
raw, err := b.getBlockRaw(hash, 0, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -579,12 +579,12 @@ func (b *EthereumRPC) GetBlockInfo(hash string) (*bchain.BlockInfo, error) {
|
|||
|
||||
// GetTransactionForMempool returns a transaction by the transaction ID.
|
||||
// It could be optimized for mempool, i.e. without block time and confirmations
|
||||
func (b *EthereumRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) {
|
||||
func (b *EnergiRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) {
|
||||
return b.GetTransaction(txid)
|
||||
}
|
||||
|
||||
// GetTransaction returns a transaction by the transaction ID.
|
||||
func (b *EthereumRPC) GetTransaction(txid string) (*bchain.Tx, error) {
|
||||
func (b *EnergiRPC) GetTransaction(txid string) (*bchain.Tx, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
|
||||
defer cancel()
|
||||
var tx *rpcTransaction
|
||||
|
@ -647,7 +647,7 @@ func (b *EthereumRPC) GetTransaction(txid string) (*bchain.Tx, error) {
|
|||
}
|
||||
|
||||
// GetTransactionSpecific returns json as returned by backend, with all coin specific data
|
||||
func (b *EthereumRPC) GetTransactionSpecific(tx *bchain.Tx) (json.RawMessage, error) {
|
||||
func (b *EnergiRPC) GetTransactionSpecific(tx *bchain.Tx) (json.RawMessage, error) {
|
||||
csd, ok := tx.CoinSpecificData.(completeTransaction)
|
||||
if !ok {
|
||||
ntx, err := b.GetTransaction(tx.Txid)
|
||||
|
@ -664,7 +664,7 @@ func (b *EthereumRPC) GetTransactionSpecific(tx *bchain.Tx) (json.RawMessage, er
|
|||
}
|
||||
|
||||
// GetMempoolTransactions returns transactions in mempool
|
||||
func (b *EthereumRPC) GetMempoolTransactions() ([]string, error) {
|
||||
func (b *EnergiRPC) GetMempoolTransactions() ([]string, error) {
|
||||
raw, err := b.getBlockRaw("pending", 0, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -679,12 +679,12 @@ func (b *EthereumRPC) GetMempoolTransactions() ([]string, error) {
|
|||
}
|
||||
|
||||
// EstimateFee returns fee estimation
|
||||
func (b *EthereumRPC) EstimateFee(blocks int) (big.Int, error) {
|
||||
func (b *EnergiRPC) EstimateFee(blocks int) (big.Int, error) {
|
||||
return b.EstimateSmartFee(blocks, true)
|
||||
}
|
||||
|
||||
// EstimateSmartFee returns fee estimation
|
||||
func (b *EthereumRPC) EstimateSmartFee(blocks int, conservative bool) (big.Int, error) {
|
||||
func (b *EnergiRPC) EstimateSmartFee(blocks int, conservative bool) (big.Int, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
|
||||
defer cancel()
|
||||
var r big.Int
|
||||
|
@ -705,7 +705,7 @@ func getStringFromMap(p string, params map[string]interface{}) (string, bool) {
|
|||
}
|
||||
|
||||
// EthereumTypeEstimateGas returns estimation of gas consumption for given transaction parameters
|
||||
func (b *EthereumRPC) EthereumTypeEstimateGas(params map[string]interface{}) (uint64, error) {
|
||||
func (b *EnergiRPC) EthereumTypeEstimateGas(params map[string]interface{}) (uint64, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
|
||||
defer cancel()
|
||||
msg := ethereum.CallMsg{}
|
||||
|
@ -738,7 +738,7 @@ func (b *EthereumRPC) EthereumTypeEstimateGas(params map[string]interface{}) (ui
|
|||
}
|
||||
|
||||
// SendRawTransaction sends raw transaction
|
||||
func (b *EthereumRPC) SendRawTransaction(hex string) (string, error) {
|
||||
func (b *EnergiRPC) SendRawTransaction(hex string) (string, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
|
||||
defer cancel()
|
||||
var raw json.RawMessage
|
||||
|
@ -759,26 +759,26 @@ func (b *EthereumRPC) SendRawTransaction(hex string) (string, error) {
|
|||
}
|
||||
|
||||
// EthereumTypeGetBalance returns current balance of an address
|
||||
func (b *EthereumRPC) EthereumTypeGetBalance(addrDesc bchain.AddressDescriptor) (*big.Int, error) {
|
||||
func (b *EnergiRPC) EthereumTypeGetBalance(addrDesc bchain.AddressDescriptor) (*big.Int, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
|
||||
defer cancel()
|
||||
return b.client.BalanceAt(ctx, ethcommon.BytesToAddress(addrDesc), nil)
|
||||
}
|
||||
|
||||
// EthereumTypeGetNonce returns current balance of an address
|
||||
func (b *EthereumRPC) EthereumTypeGetNonce(addrDesc bchain.AddressDescriptor) (uint64, error) {
|
||||
func (b *EnergiRPC) EthereumTypeGetNonce(addrDesc bchain.AddressDescriptor) (uint64, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
|
||||
defer cancel()
|
||||
return b.client.NonceAt(ctx, ethcommon.BytesToAddress(addrDesc), nil)
|
||||
}
|
||||
|
||||
// GetChainParser returns ethereum BlockChainParser
|
||||
func (b *EthereumRPC) GetChainParser() bchain.BlockChainParser {
|
||||
func (b *EnergiRPC) GetChainParser() bchain.BlockChainParser {
|
||||
return b.Parser
|
||||
}
|
||||
|
||||
// GetChainParser returns ethereum block header by number.
|
||||
func (b *EthereumRPC) headerByNumber(ctx context.Context, number *big.Int) (*header, error) {
|
||||
func (b *EnergiRPC) headerByNumber(ctx context.Context, number *big.Int) (*header, error) {
|
||||
var head header
|
||||
err := b.rpc.CallContext(ctx, &head, "eth_getBlockByNumber", toBlockNumArg(number), false)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue