diff --git a/Gopkg.lock b/Gopkg.lock index 0aef3526..fb28e79a 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -31,6 +31,18 @@ packages = [".","base58","bech32"] revision = "501929d3d046174c3d39f0ea54ece471aa17238c" +[[projects]] + name = "github.com/ethereum/go-ethereum" + packages = [".","common","common/hexutil","common/math","core/types","crypto","crypto/secp256k1","crypto/sha3","ethclient","ethdb","log","metrics","params","rlp","rpc","trie"] + revision = "b8b9f7f4476a30a0aaf6077daade6ae77f969960" + version = "v1.8.2" + +[[projects]] + name = "github.com/go-stack/stack" + packages = ["."] + revision = "259ab82a6cad3992b4e21ff5cac294ccb06474bc" + version = "v1.7.0" + [[projects]] branch = "master" name = "github.com/golang/glog" @@ -43,6 +55,12 @@ revision = "925541529c1fa6821df4e44ce2723319eb2be768" version = "v1.0.0" +[[projects]] + branch = "master" + name = "github.com/golang/snappy" + packages = ["."] + revision = "553a641470496b2327abcac10b36396bd98e45c9" + [[projects]] name = "github.com/gorilla/context" packages = ["."] @@ -115,6 +133,18 @@ packages = [".","internal/util","nfs","xfs"] revision = "54d17b57dd7d4a3aa092476596b3f8a933bde349" +[[projects]] + name = "github.com/rs/cors" + packages = ["."] + revision = "feef513b9575b32f84bafa580aad89b011259019" + version = "v1.3.0" + +[[projects]] + branch = "master" + name = "github.com/syndtr/goleveldb" + packages = ["leveldb","leveldb/cache","leveldb/comparer","leveldb/errors","leveldb/filter","leveldb/iterator","leveldb/journal","leveldb/memdb","leveldb/opt","leveldb/storage","leveldb/table","leveldb/util"] + revision = "169b1b37be738edb2813dab48c97a549bcf99bb5" + [[projects]] branch = "master" name = "github.com/tecbot/gorocksdb" @@ -127,9 +157,33 @@ packages = ["ripemd160"] revision = "182114d582623c1caa54f73de9c7224e23a48487" +[[projects]] + branch = "master" + name = "golang.org/x/net" + packages = ["websocket"] + revision = "e0c57d8f86c17f0724497efcb3bc617e82834821" + +[[projects]] + name = "gopkg.in/fatih/set.v0" + packages = ["."] + revision = "57907de300222151a123d29255ed17f5ed43fad3" + version = "v0.1.0" + +[[projects]] + branch = "v2" + name = "gopkg.in/karalabe/cookiejar.v2" + packages = ["collections/prque"] + revision = "8dcd6a7f4951f6ff3ee9cbb919a06d8925822e57" + +[[projects]] + branch = "v2" + name = "gopkg.in/natefinch/npipe.v2" + packages = ["."] + revision = "c1b8fa8bdccecb0b8db834ee0b92fdbcfa606dd6" + [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "f9c35644f433ae6183ea2730bb4f49027d62085a1e9c67f410941ce267a3cc1c" + inputs-digest = "82a83b024230447e13a6c44c1682be3009d9309da76ea6f273092ee44bf3d6d6" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 19f9ffa2..54e4074c 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -64,3 +64,7 @@ [[constraint]] branch = "master" name = "github.com/tecbot/gorocksdb" + +[[constraint]] + name = "github.com/ethereum/go-ethereum" + version = "1.8.2" diff --git a/bchain/coins/blockchain.go b/bchain/coins/blockchain.go index c2bb4d99..4d8787f3 100644 --- a/bchain/coins/blockchain.go +++ b/bchain/coins/blockchain.go @@ -3,6 +3,7 @@ package coins import ( "blockbook/bchain" "blockbook/bchain/coins/btc" + "blockbook/bchain/coins/eth" "blockbook/bchain/coins/zec" "blockbook/common" "fmt" @@ -20,6 +21,8 @@ func init() { blockChainFactories["btc"] = btc.NewBitcoinRPC blockChainFactories["btc-testnet"] = btc.NewBitcoinRPC blockChainFactories["zec"] = zec.NewZCashRPC + blockChainFactories["eth"] = eth.NewEthRPC + blockChainFactories["eth-testnet"] = eth.NewEthRPC } // NewBlockChain creates bchain.BlockChain of type defined by parameter coin diff --git a/bchain/coins/eth/ethparser.go b/bchain/coins/eth/ethparser.go new file mode 100644 index 00000000..0f0bd136 --- /dev/null +++ b/bchain/coins/eth/ethparser.go @@ -0,0 +1,30 @@ +package eth + +import "blockbook/bchain" + +type EthParser struct { +} + +func (p *EthParser) AddressToOutputScript(address string) ([]byte, error) { + panic("not implemented") +} + +func (p *EthParser) OutputScriptToAddresses(script []byte) ([]string, error) { + panic("not implemented") +} + +func (p *EthParser) ParseTx(b []byte) (*bchain.Tx, error) { + panic("not implemented") +} + +func (p *EthParser) ParseBlock(b []byte) (*bchain.Block, error) { + panic("not implemented") +} + +func (p *EthParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) ([]byte, error) { + panic("not implemented") +} + +func (p *EthParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) { + panic("not implemented") +} diff --git a/bchain/coins/eth/ethrpc.go b/bchain/coins/eth/ethrpc.go new file mode 100644 index 00000000..53237944 --- /dev/null +++ b/bchain/coins/eth/ethrpc.go @@ -0,0 +1,120 @@ +package eth + +import ( + "blockbook/bchain" + "blockbook/common" + "time" + + "github.com/ethereum/go-ethereum/ethclient" +) + +// EthRPC is an interface to JSON-RPC eth service. +type EthRPC struct { + client *ethclient.Client + rpcURL string + user string + password string + Parser *EthParser + Testnet bool + Network string + Mempool *bchain.Mempool + ParseBlocks bool + metrics *common.Metrics +} + +// NewEthRPC returns new EthRPC instance. +func NewEthRPC(url string, user string, password string, timeout time.Duration, parse bool, metrics *common.Metrics) (bchain.BlockChain, error) { + c, err := ethclient.Dial(url) + if err != nil { + return nil, err + } + s := &EthRPC{ + client: c, + rpcURL: url, + user: user, + password: password, + ParseBlocks: parse, + metrics: metrics, + } + + // always create parser + s.Parser = &EthParser{} + + // // parameters for getInfo request + // if s.Parser.Params.Net == wire.MainNet { + // s.Testnet = false + // s.Network = "livenet" + // } else { + // s.Testnet = true + // s.Network = "testnet" + // } + + // s.Mempool = bchain.NewMempool(s, metrics) + + // glog.Info("rpc: block chain ", s.Parser.Params.Name) + return s, nil +} + +func (b *EthRPC) IsTestnet() bool { + panic("not implemented") +} + +func (b *EthRPC) GetNetworkName() string { + panic("not implemented") +} + +func (b *EthRPC) GetBestBlockHash() (string, error) { + panic("not implemented") +} + +func (b *EthRPC) GetBestBlockHeight() (uint32, error) { + panic("not implemented") +} + +func (b *EthRPC) GetBlockHash(height uint32) (string, error) { + panic("not implemented") +} + +func (b *EthRPC) GetBlockHeader(hash string) (*bchain.BlockHeader, error) { + panic("not implemented") +} + +func (b *EthRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) { + panic("not implemented") +} + +func (b *EthRPC) GetMempool() ([]string, error) { + panic("not implemented") +} + +func (b *EthRPC) GetTransaction(txid string) (*bchain.Tx, error) { + panic("not implemented") +} + +func (b *EthRPC) EstimateSmartFee(blocks int, conservative bool) (float64, error) { + panic("not implemented") +} + +func (b *EthRPC) SendRawTransaction(tx string) (string, error) { + panic("not implemented") +} + +func (b *EthRPC) ResyncMempool(onNewTxAddr func(txid string, addr string)) error { + panic("not implemented") +} + +func (b *EthRPC) GetMempoolTransactions(outputScript []byte) ([]string, error) { + panic("not implemented") +} + +func (b *EthRPC) GetMempoolSpentOutput(outputTxid string, vout uint32) string { + panic("not implemented") +} + +func (b *EthRPC) GetMempoolEntry(txid string) (*bchain.MempoolEntry, error) { + panic("not implemented") +} + +func (b *EthRPC) GetChainParser() bchain.BlockChainParser { + panic("not implemented") +}