Prefer all caps for initialisms and acronyms
This commit is contained in:
+2
-2
@@ -32,7 +32,7 @@ import (
|
||||
var (
|
||||
ErrInvalidAbiFile = errors.New("invalid abi")
|
||||
ErrMissingAbiFile = errors.New("missing abi")
|
||||
ErrApiRequestFailed = errors.New("etherscan api request failed")
|
||||
ErrAPIRequestFailed = errors.New("etherscan api request failed")
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
@@ -72,7 +72,7 @@ func (e *EtherScanAPI) GetAbi(contractHash string) (string, error) {
|
||||
request := fmt.Sprintf("%s/api?module=contract&action=getabi&address=%s", e.url, contractHash)
|
||||
r, err := e.client.Get(request)
|
||||
if err != nil {
|
||||
return "", ErrApiRequestFailed
|
||||
return "", ErrAPIRequestFailed
|
||||
}
|
||||
defer r.Body.Close()
|
||||
err = json.NewDecoder(r.Body).Decode(&target)
|
||||
|
||||
@@ -41,11 +41,11 @@ type BlockChain struct {
|
||||
ethClient core.EthClient
|
||||
headerConverter vulcCommon.HeaderConverter
|
||||
node core.Node
|
||||
rpcClient core.RpcClient
|
||||
rpcClient core.RPCClient
|
||||
transactionConverter vulcCommon.TransactionConverter
|
||||
}
|
||||
|
||||
func NewBlockChain(ethClient core.EthClient, rpcClient core.RpcClient, node core.Node, converter vulcCommon.TransactionConverter) *BlockChain {
|
||||
func NewBlockChain(ethClient core.EthClient, rpcClient core.RPCClient, node core.Node, converter vulcCommon.TransactionConverter) *BlockChain {
|
||||
return &BlockChain{
|
||||
blockConverter: vulcCommon.NewBlockConverter(converter),
|
||||
ethClient: ethClient,
|
||||
@@ -108,7 +108,7 @@ func (blockChain *BlockChain) GetFullSyncLogs(contract core.Contract, startingBl
|
||||
func (blockChain *BlockChain) GetTransactions(transactionHashes []common.Hash) ([]core.TransactionModel, error) {
|
||||
numTransactions := len(transactionHashes)
|
||||
var batch []client.BatchElem
|
||||
transactions := make([]core.RpcTransaction, numTransactions)
|
||||
transactions := make([]core.RPCTransaction, numTransactions)
|
||||
|
||||
for index, transactionHash := range transactionHashes {
|
||||
batchElem := client.BatchElem{
|
||||
@@ -124,7 +124,7 @@ func (blockChain *BlockChain) GetTransactions(transactionHashes []common.Hash) (
|
||||
return []core.TransactionModel{}, rpcErr
|
||||
}
|
||||
|
||||
return blockChain.transactionConverter.ConvertRpcTransactionsToModels(transactions)
|
||||
return blockChain.transactionConverter.ConvertRPCTransactionsToModels(transactions)
|
||||
}
|
||||
|
||||
func (blockChain *BlockChain) LastBlock() (*big.Int, error) {
|
||||
|
||||
@@ -37,14 +37,14 @@ var _ = Describe("Geth blockchain", func() {
|
||||
var (
|
||||
mockClient *fakes.MockEthClient
|
||||
blockChain *eth.BlockChain
|
||||
mockRpcClient *fakes.MockRpcClient
|
||||
mockRpcClient *fakes.MockRPCClient
|
||||
mockTransactionConverter *fakes.MockTransactionConverter
|
||||
node vulcCore.Node
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
mockClient = fakes.NewMockEthClient()
|
||||
mockRpcClient = fakes.NewMockRpcClient()
|
||||
mockRpcClient = fakes.NewMockRPCClient()
|
||||
mockTransactionConverter = fakes.NewMockTransactionConverter()
|
||||
node = vulcCore.Node{}
|
||||
blockChain = eth.NewBlockChain(mockClient, mockRpcClient, node, mockTransactionConverter)
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
||||
type RpcClient struct {
|
||||
type RPCClient struct {
|
||||
client *rpc.Client
|
||||
ipcPath string
|
||||
}
|
||||
@@ -36,14 +36,14 @@ type BatchElem struct {
|
||||
Error error
|
||||
}
|
||||
|
||||
func NewRpcClient(client *rpc.Client, ipcPath string) RpcClient {
|
||||
return RpcClient{
|
||||
func NewRPCClient(client *rpc.Client, ipcPath string) RPCClient {
|
||||
return RPCClient{
|
||||
client: client,
|
||||
ipcPath: ipcPath,
|
||||
}
|
||||
}
|
||||
|
||||
func (client RpcClient) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error {
|
||||
func (client RPCClient) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error {
|
||||
//If an empty interface (or other nil object) is passed to CallContext, when the JSONRPC message is created the params will
|
||||
//be interpreted as [null]. This seems to work fine for most of the ethereum clients (which presumably ignore a null parameter.
|
||||
//Ganache however does not ignore it, and throws an 'Incorrect number of arguments' error.
|
||||
@@ -53,15 +53,15 @@ func (client RpcClient) CallContext(ctx context.Context, result interface{}, met
|
||||
return client.client.CallContext(ctx, result, method, args...)
|
||||
}
|
||||
|
||||
func (client RpcClient) IpcPath() string {
|
||||
func (client RPCClient) IpcPath() string {
|
||||
return client.ipcPath
|
||||
}
|
||||
|
||||
func (client RpcClient) SupportedModules() (map[string]string, error) {
|
||||
func (client RPCClient) SupportedModules() (map[string]string, error) {
|
||||
return client.client.SupportedModules()
|
||||
}
|
||||
|
||||
func (client RpcClient) BatchCall(batch []BatchElem) error {
|
||||
func (client RPCClient) BatchCall(batch []BatchElem) error {
|
||||
var rpcBatch []rpc.BatchElem
|
||||
for _, batchElem := range batch {
|
||||
var newBatchElem = rpc.BatchElem{
|
||||
@@ -78,7 +78,7 @@ func (client RpcClient) BatchCall(batch []BatchElem) error {
|
||||
|
||||
// Subscribe subscribes to an rpc "namespace_subscribe" subscription with the given channel
|
||||
// The first argument needs to be the method we wish to invoke
|
||||
func (client RpcClient) Subscribe(namespace string, payloadChan interface{}, args ...interface{}) (*rpc.ClientSubscription, error) {
|
||||
func (client RPCClient) Subscribe(namespace string, payloadChan interface{}, args ...interface{}) (*rpc.ClientSubscription, error) {
|
||||
chanVal := reflect.ValueOf(payloadChan)
|
||||
if chanVal.Kind() != reflect.Chan || chanVal.Type().ChanDir()&reflect.SendDir == 0 {
|
||||
return nil, errors.New("second argument to Subscribe must be a writable channel")
|
||||
|
||||
@@ -38,16 +38,16 @@ func NewColdImporter(ethDB ethereum.Database, blockRepository datastore.BlockRep
|
||||
}
|
||||
}
|
||||
|
||||
func (ci *ColdImporter) Execute(startingBlockNumber int64, endingBlockNumber int64, nodeId string) error {
|
||||
missingBlocks := ci.blockRepository.MissingBlockNumbers(startingBlockNumber, endingBlockNumber, nodeId)
|
||||
func (ci *ColdImporter) Execute(startingBlockNumber int64, endingBlockNumber int64, nodeID string) error {
|
||||
missingBlocks := ci.blockRepository.MissingBlockNumbers(startingBlockNumber, endingBlockNumber, nodeID)
|
||||
for _, n := range missingBlocks {
|
||||
hash := ci.ethDB.GetBlockHash(n)
|
||||
|
||||
blockId, err := ci.createBlocksAndTransactions(hash, n)
|
||||
blockID, err := ci.createBlocksAndTransactions(hash, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ci.createReceiptsAndLogs(hash, n, blockId)
|
||||
err = ci.createReceiptsAndLogs(hash, n, blockID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -65,11 +65,11 @@ func (ci *ColdImporter) createBlocksAndTransactions(hash []byte, i int64) (int64
|
||||
return ci.blockRepository.CreateOrUpdateBlock(coreBlock)
|
||||
}
|
||||
|
||||
func (ci *ColdImporter) createReceiptsAndLogs(hash []byte, number int64, blockId int64) error {
|
||||
func (ci *ColdImporter) createReceiptsAndLogs(hash []byte, number int64, blockID int64) error {
|
||||
receipts := ci.ethDB.GetBlockReceipts(hash, number)
|
||||
coreReceipts, err := common.ToCoreReceipts(receipts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ci.receiptRepository.CreateReceiptsAndLogs(blockId, coreReceipts)
|
||||
return ci.receiptRepository.CreateReceiptsAndLogs(blockID, coreReceipts)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
|
||||
const (
|
||||
ColdImportClientName = "LevelDbColdImport"
|
||||
ColdImportNetworkId float64 = 1
|
||||
ColdImportNetworkID float64 = 1
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -54,15 +54,15 @@ func (cinb ColdImportNodeBuilder) GetNode(genesisBlock []byte, levelPath string)
|
||||
if err != nil {
|
||||
return coldNode, err
|
||||
}
|
||||
nodeId, err := cinb.parser.ParsePublicKey(string(nodeKey))
|
||||
nodeID, err := cinb.parser.ParsePublicKey(string(nodeKey))
|
||||
if err != nil {
|
||||
return coldNode, err
|
||||
}
|
||||
genesisBlockHash := common.BytesToHash(genesisBlock).String()
|
||||
coldNode = core.Node{
|
||||
GenesisBlock: genesisBlockHash,
|
||||
NetworkID: ColdImportNetworkId,
|
||||
ID: nodeId,
|
||||
NetworkID: ColdImportNetworkID,
|
||||
ID: nodeID,
|
||||
ClientName: ColdImportClientName,
|
||||
}
|
||||
return coldNode, nil
|
||||
|
||||
@@ -106,7 +106,7 @@ var _ = Describe("Cold importer node builder", func() {
|
||||
expectedGenesisBlock := common.BytesToHash(fakeGenesisBlock).String()
|
||||
Expect(result.GenesisBlock).To(Equal(expectedGenesisBlock))
|
||||
Expect(result.ID).To(Equal(fakePublicKeyString))
|
||||
Expect(result.NetworkID).To(Equal(cold_import.ColdImportNetworkId))
|
||||
Expect(result.NetworkID).To(Equal(cold_import.ColdImportNetworkID))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ func (cdtc *ColdDbTransactionConverter) ConvertBlockTransactionsToCore(gethBlock
|
||||
return coreTransactions, nil
|
||||
}
|
||||
|
||||
func (cdtc *ColdDbTransactionConverter) ConvertRpcTransactionsToModels(transactions []core.RpcTransaction) ([]core.TransactionModel, error) {
|
||||
func (cdtc *ColdDbTransactionConverter) ConvertRPCTransactionsToModels(transactions []core.RPCTransaction) ([]core.TransactionModel, error) {
|
||||
panic("converting transaction indexes to integer not supported for cold import")
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
}
|
||||
block := types.NewBlock(&header, []*types.Transaction{}, []*types.Header{}, []*types.Receipt{})
|
||||
client := fakes.NewMockEthClient()
|
||||
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
||||
transactionConverter := rpc.NewRPCTransactionConverter(client)
|
||||
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
||||
|
||||
coreBlock, err := blockConverter.ToCoreBlock(block)
|
||||
@@ -110,7 +110,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
}
|
||||
uncles := []*types.Header{{Number: big.NewInt(1071817)}, {Number: big.NewInt(1071818)}}
|
||||
block := types.NewBlock(&header, transactions, uncles, []*types.Receipt{&receipt})
|
||||
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
||||
transactionConverter := rpc.NewRPCTransactionConverter(client)
|
||||
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
||||
|
||||
coreBlock, err := blockConverter.ToCoreBlock(block)
|
||||
@@ -151,7 +151,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
|
||||
client := fakes.NewMockEthClient()
|
||||
client.SetTransactionReceipts(receipts)
|
||||
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
||||
transactionConverter := rpc.NewRPCTransactionConverter(client)
|
||||
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
||||
|
||||
coreBlock, err := blockConverter.ToCoreBlock(block)
|
||||
@@ -211,7 +211,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
|
||||
client := fakes.NewMockEthClient()
|
||||
client.SetTransactionReceipts(receipts)
|
||||
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
||||
transactionConverter := rpc.NewRPCTransactionConverter(client)
|
||||
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
||||
|
||||
coreBlock, err := blockConverter.ToCoreBlock(block)
|
||||
@@ -229,7 +229,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
header := types.Header{}
|
||||
block := types.NewBlock(&header, []*types.Transaction{}, []*types.Header{}, []*types.Receipt{})
|
||||
client := fakes.NewMockEthClient()
|
||||
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
||||
transactionConverter := rpc.NewRPCTransactionConverter(client)
|
||||
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
||||
|
||||
coreBlock, err := blockConverter.ToCoreBlock(block)
|
||||
@@ -270,7 +270,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
[]*types.Header{},
|
||||
[]*types.Receipt{gethReceipt},
|
||||
)
|
||||
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
||||
transactionConverter := rpc.NewRPCTransactionConverter(client)
|
||||
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
||||
|
||||
coreBlock, err := blockConverter.ToCoreBlock(block)
|
||||
@@ -320,7 +320,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
[]*types.Header{},
|
||||
[]*types.Receipt{gethReceipt},
|
||||
)
|
||||
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
||||
transactionConverter := rpc.NewRPCTransactionConverter(client)
|
||||
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
||||
|
||||
coreBlock, err := blockConverter.ToCoreBlock(block)
|
||||
@@ -370,7 +370,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
It("returns an error when transaction sender call fails", func() {
|
||||
client := fakes.NewMockEthClient()
|
||||
client.SetTransactionSenderErr(fakes.FakeError)
|
||||
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
||||
transactionConverter := rpc.NewRPCTransactionConverter(client)
|
||||
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
||||
|
||||
_, err := blockConverter.ToCoreBlock(block)
|
||||
@@ -381,7 +381,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
It("returns an error when transaction receipt call fails", func() {
|
||||
client := fakes.NewMockEthClient()
|
||||
client.SetTransactionReceiptErr(fakes.FakeError)
|
||||
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
||||
transactionConverter := rpc.NewRPCTransactionConverter(client)
|
||||
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
||||
|
||||
_, err := blockConverter.ToCoreBlock(block)
|
||||
|
||||
@@ -23,5 +23,5 @@ import (
|
||||
|
||||
type TransactionConverter interface {
|
||||
ConvertBlockTransactionsToCore(gethBlock *types.Block) ([]core.TransactionModel, error)
|
||||
ConvertRpcTransactionsToModels(transactions []core.RpcTransaction) ([]core.TransactionModel, error)
|
||||
ConvertRPCTransactionsToModels(transactions []core.RPCTransaction) ([]core.TransactionModel, error)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import (
|
||||
vulcCommon "github.com/vulcanize/vulcanizedb/pkg/eth/converters/common"
|
||||
)
|
||||
|
||||
type RpcTransactionConverter struct {
|
||||
type RPCTransactionConverter struct {
|
||||
client core.EthClient
|
||||
}
|
||||
|
||||
@@ -51,11 +51,11 @@ type transactionData struct {
|
||||
S *big.Int
|
||||
}
|
||||
|
||||
func NewRpcTransactionConverter(client core.EthClient) *RpcTransactionConverter {
|
||||
return &RpcTransactionConverter{client: client}
|
||||
func NewRPCTransactionConverter(client core.EthClient) *RPCTransactionConverter {
|
||||
return &RPCTransactionConverter{client: client}
|
||||
}
|
||||
|
||||
func (converter *RpcTransactionConverter) ConvertRpcTransactionsToModels(transactions []core.RpcTransaction) ([]core.TransactionModel, error) {
|
||||
func (converter *RPCTransactionConverter) ConvertRPCTransactionsToModels(transactions []core.RPCTransaction) ([]core.TransactionModel, error) {
|
||||
var results []core.TransactionModel
|
||||
for _, transaction := range transactions {
|
||||
txData, convertErr := getTransactionData(transaction)
|
||||
@@ -88,7 +88,7 @@ func (converter *RpcTransactionConverter) ConvertRpcTransactionsToModels(transac
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (converter *RpcTransactionConverter) ConvertBlockTransactionsToCore(gethBlock *types.Block) ([]core.TransactionModel, error) {
|
||||
func (converter *RPCTransactionConverter) ConvertBlockTransactionsToCore(gethBlock *types.Block) ([]core.TransactionModel, error) {
|
||||
var g errgroup.Group
|
||||
coreTransactions := make([]core.TransactionModel, len(gethBlock.Transactions()))
|
||||
|
||||
@@ -122,8 +122,8 @@ func (converter *RpcTransactionConverter) ConvertBlockTransactionsToCore(gethBlo
|
||||
return coreTransactions, nil
|
||||
}
|
||||
|
||||
func (rtc *RpcTransactionConverter) appendReceiptToTransaction(transaction core.TransactionModel) (core.TransactionModel, error) {
|
||||
gethReceipt, err := rtc.client.TransactionReceipt(context.Background(), common.HexToHash(transaction.Hash))
|
||||
func (converter *RPCTransactionConverter) appendReceiptToTransaction(transaction core.TransactionModel) (core.TransactionModel, error) {
|
||||
gethReceipt, err := converter.client.TransactionReceipt(context.Background(), common.HexToHash(transaction.Hash))
|
||||
if err != nil {
|
||||
return transaction, err
|
||||
}
|
||||
@@ -155,7 +155,7 @@ func convertGethTransactionToModel(transaction *types.Transaction, from *common.
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getTransactionData(transaction core.RpcTransaction) (transactionData, error) {
|
||||
func getTransactionData(transaction core.RPCTransaction) (transactionData, error) {
|
||||
nonce, nonceErr := hexToBigInt(transaction.Nonce)
|
||||
if nonceErr != nil {
|
||||
return transactionData{}, nonceErr
|
||||
|
||||
@@ -25,16 +25,16 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("RPC transaction converter", func() {
|
||||
var converter rpc.RpcTransactionConverter
|
||||
var converter rpc.RPCTransactionConverter
|
||||
|
||||
BeforeEach(func() {
|
||||
converter = rpc.RpcTransactionConverter{}
|
||||
converter = rpc.RPCTransactionConverter{}
|
||||
})
|
||||
|
||||
It("converts hex fields to integers", func() {
|
||||
rpcTransaction := getFakeRpcTransaction("0x1")
|
||||
|
||||
transactionModels, err := converter.ConvertRpcTransactionsToModels([]core.RpcTransaction{rpcTransaction})
|
||||
transactionModels, err := converter.ConvertRPCTransactionsToModels([]core.RPCTransaction{rpcTransaction})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(transactionModels)).To(Equal(1))
|
||||
@@ -48,7 +48,7 @@ var _ = Describe("RPC transaction converter", func() {
|
||||
It("returns error if invalid hex cannot be converted", func() {
|
||||
invalidTransaction := getFakeRpcTransaction("invalid")
|
||||
|
||||
_, err := converter.ConvertRpcTransactionsToModels([]core.RpcTransaction{invalidTransaction})
|
||||
_, err := converter.ConvertRPCTransactionsToModels([]core.RPCTransaction{invalidTransaction})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
@@ -56,7 +56,7 @@ var _ = Describe("RPC transaction converter", func() {
|
||||
It("copies RPC transaction hash, from, and to values to model", func() {
|
||||
rpcTransaction := getFakeRpcTransaction("0x1")
|
||||
|
||||
transactionModels, err := converter.ConvertRpcTransactionsToModels([]core.RpcTransaction{rpcTransaction})
|
||||
transactionModels, err := converter.ConvertRPCTransactionsToModels([]core.RPCTransaction{rpcTransaction})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(transactionModels)).To(Equal(1))
|
||||
@@ -67,7 +67,7 @@ var _ = Describe("RPC transaction converter", func() {
|
||||
|
||||
It("derives transaction RLP", func() {
|
||||
// actual transaction: https://kovan.etherscan.io/tx/0x3b29ef265425d304069c57e5145cd1c7558568b06d231775f50a693bee1aad4f
|
||||
rpcTransaction := core.RpcTransaction{
|
||||
rpcTransaction := core.RPCTransaction{
|
||||
Nonce: "0x7aa9",
|
||||
GasPrice: "0x3b9aca00",
|
||||
GasLimit: "0x7a120",
|
||||
@@ -82,7 +82,7 @@ var _ = Describe("RPC transaction converter", func() {
|
||||
TransactionIndex: "0xa",
|
||||
}
|
||||
|
||||
transactionModels, err := converter.ConvertRpcTransactionsToModels([]core.RpcTransaction{rpcTransaction})
|
||||
transactionModels, err := converter.ConvertRPCTransactionsToModels([]core.RPCTransaction{rpcTransaction})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(transactionModels)).To(Equal(1))
|
||||
@@ -98,7 +98,7 @@ var _ = Describe("RPC transaction converter", func() {
|
||||
It("does not include transaction receipt", func() {
|
||||
rpcTransaction := getFakeRpcTransaction("0x1")
|
||||
|
||||
transactionModels, err := converter.ConvertRpcTransactionsToModels([]core.RpcTransaction{rpcTransaction})
|
||||
transactionModels, err := converter.ConvertRPCTransactionsToModels([]core.RPCTransaction{rpcTransaction})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(transactionModels)).To(Equal(1))
|
||||
@@ -106,8 +106,8 @@ var _ = Describe("RPC transaction converter", func() {
|
||||
})
|
||||
})
|
||||
|
||||
func getFakeRpcTransaction(hex string) core.RpcTransaction {
|
||||
return core.RpcTransaction{
|
||||
func getFakeRpcTransaction(hex string) core.RPCTransaction {
|
||||
return core.RPCTransaction{
|
||||
Hash: "0x2",
|
||||
Amount: hex,
|
||||
GasLimit: hex,
|
||||
|
||||
+11
-11
@@ -33,12 +33,12 @@ import (
|
||||
|
||||
type IPropertiesReader interface {
|
||||
NodeInfo() (id string, name string)
|
||||
NetworkId() float64
|
||||
NetworkID() float64
|
||||
GenesisBlock() string
|
||||
}
|
||||
|
||||
type PropertiesReader struct {
|
||||
client core.RpcClient
|
||||
client core.RPCClient
|
||||
}
|
||||
|
||||
type ParityClient struct {
|
||||
@@ -57,18 +57,18 @@ type GanacheClient struct {
|
||||
PropertiesReader
|
||||
}
|
||||
|
||||
func MakeNode(rpcClient core.RpcClient) core.Node {
|
||||
func MakeNode(rpcClient core.RPCClient) core.Node {
|
||||
pr := makePropertiesReader(rpcClient)
|
||||
id, name := pr.NodeInfo()
|
||||
return core.Node{
|
||||
GenesisBlock: pr.GenesisBlock(),
|
||||
NetworkID: pr.NetworkId(),
|
||||
NetworkID: pr.NetworkID(),
|
||||
ID: id,
|
||||
ClientName: name,
|
||||
}
|
||||
}
|
||||
|
||||
func makePropertiesReader(client core.RpcClient) IPropertiesReader {
|
||||
func makePropertiesReader(client core.RPCClient) IPropertiesReader {
|
||||
switch getNodeType(client) {
|
||||
case core.GETH:
|
||||
return GethClient{PropertiesReader: PropertiesReader{client: client}}
|
||||
@@ -83,7 +83,7 @@ func makePropertiesReader(client core.RpcClient) IPropertiesReader {
|
||||
}
|
||||
}
|
||||
|
||||
func getNodeType(client core.RpcClient) core.NodeType {
|
||||
func getNodeType(client core.RPCClient) core.NodeType {
|
||||
if strings.Contains(client.IpcPath(), "infura") {
|
||||
return core.INFURA
|
||||
}
|
||||
@@ -97,14 +97,14 @@ func getNodeType(client core.RpcClient) core.NodeType {
|
||||
return core.PARITY
|
||||
}
|
||||
|
||||
func (reader PropertiesReader) NetworkId() float64 {
|
||||
func (reader PropertiesReader) NetworkID() float64 {
|
||||
var version string
|
||||
err := reader.client.CallContext(context.Background(), &version, "net_version")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
networkId, _ := strconv.ParseFloat(version, 64)
|
||||
return networkId
|
||||
networkID, _ := strconv.ParseFloat(version, 64)
|
||||
return networkID
|
||||
}
|
||||
|
||||
func (reader PropertiesReader) GenesisBlock() string {
|
||||
@@ -142,10 +142,10 @@ func (client ParityClient) parityNodeInfo() string {
|
||||
}
|
||||
|
||||
func (client ParityClient) parityID() string {
|
||||
var enodeId = regexp.MustCompile(`^enode://(.+)@.+$`)
|
||||
var enodeID = regexp.MustCompile(`^enode://(.+)@.+$`)
|
||||
var enodeURL string
|
||||
client.client.CallContext(context.Background(), &enodeURL, "parity_enode")
|
||||
enode := enodeId.FindStringSubmatch(enodeURL)
|
||||
enode := enodeID.FindStringSubmatch(enodeURL)
|
||||
if len(enode) < 2 {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ var _ = Describe("Node Info", func() {
|
||||
})
|
||||
|
||||
It("returns parity ID and client name for parity node", func() {
|
||||
client := fakes.NewMockRpcClient()
|
||||
client := fakes.NewMockRPCClient()
|
||||
|
||||
n := node.MakeNode(client)
|
||||
Expect(n.ID).To(Equal("ParityNode"))
|
||||
@@ -74,19 +74,19 @@ var _ = Describe("Node Info", func() {
|
||||
})
|
||||
|
||||
It("returns the genesis block for any client", func() {
|
||||
client := fakes.NewMockRpcClient()
|
||||
client := fakes.NewMockRPCClient()
|
||||
n := node.MakeNode(client)
|
||||
Expect(n.GenesisBlock).To(Equal(EmpytHeaderHash))
|
||||
})
|
||||
|
||||
It("returns the network id for any client", func() {
|
||||
client := fakes.NewMockRpcClient()
|
||||
client := fakes.NewMockRPCClient()
|
||||
n := node.MakeNode(client)
|
||||
Expect(n.NetworkID).To(Equal(float64(1234)))
|
||||
})
|
||||
|
||||
It("returns geth ID and client name for geth node", func() {
|
||||
client := fakes.NewMockRpcClient()
|
||||
client := fakes.NewMockRPCClient()
|
||||
supportedModules := make(map[string]string)
|
||||
supportedModules["admin"] = "ok"
|
||||
client.SetSupporedModules(supportedModules)
|
||||
@@ -97,7 +97,7 @@ var _ = Describe("Node Info", func() {
|
||||
})
|
||||
|
||||
It("returns infura ID and client name for infura node", func() {
|
||||
client := fakes.NewMockRpcClient()
|
||||
client := fakes.NewMockRPCClient()
|
||||
client.SetIpcPath("infura/path")
|
||||
n := node.MakeNode(client)
|
||||
Expect(n.ID).To(Equal("infura"))
|
||||
@@ -105,7 +105,7 @@ var _ = Describe("Node Info", func() {
|
||||
})
|
||||
|
||||
It("returns local id and client name for Local node", func() {
|
||||
client := fakes.NewMockRpcClient()
|
||||
client := fakes.NewMockRPCClient()
|
||||
client.SetIpcPath("127.0.0.1")
|
||||
n := node.MakeNode(client)
|
||||
Expect(n.ID).To(Equal("ganache"))
|
||||
|
||||
Reference in New Issue
Block a user