add: filecoin api schema, eth-contracts types changes

This commit is contained in:
bahadylbekov 2020-11-23 19:53:44 +03:00
parent b2e956d1d4
commit 52ec8dbd35
12 changed files with 156 additions and 89 deletions

View File

@ -3,8 +3,10 @@ package consensus
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"strconv"
"sync" "sync"
fil "github.com/Secured-Finance/dione/rpc/filecoin"
solana2 "github.com/Secured-Finance/dione/rpc/solana" solana2 "github.com/Secured-Finance/dione/rpc/solana"
"github.com/Secured-Finance/dione/beacon" "github.com/Secured-Finance/dione/beacon"
@ -21,15 +23,16 @@ import (
) )
type Miner struct { type Miner struct {
address peer.ID address peer.ID
ethAddress common.Address ethAddress common.Address
api WalletAPI api WalletAPI
mutex sync.Mutex mutex sync.Mutex
beacon beacon.BeaconNetworks beacon beacon.BeaconNetworks
ethClient *ethclient.EthereumClient ethClient *ethclient.EthereumClient
solanaClient *solana2.SolanaClient filecoinClient *fil.LotusClient
minerStake types.BigInt solanaClient *solana2.SolanaClient
networkStake types.BigInt minerStake types.BigInt
networkStake types.BigInt
} }
func NewMiner( func NewMiner(
@ -38,15 +41,17 @@ func NewMiner(
api WalletAPI, api WalletAPI,
beacon beacon.BeaconNetworks, beacon beacon.BeaconNetworks,
ethClient *ethclient.EthereumClient, ethClient *ethclient.EthereumClient,
filecoinClient *fil.LotusClient,
solanaClient *solana2.SolanaClient, solanaClient *solana2.SolanaClient,
) *Miner { ) *Miner {
return &Miner{ return &Miner{
address: address, address: address,
ethAddress: ethAddress, ethAddress: ethAddress,
api: api, api: api,
beacon: beacon, beacon: beacon,
ethClient: ethClient, ethClient: ethClient,
solanaClient: solanaClient, filecoinClient: filecoinClient,
solanaClient: solanaClient,
} }
} }
@ -102,7 +107,8 @@ func (m *Miner) MineTask(ctx context.Context, event *oracleEmitter.OracleEmitter
return nil, nil return nil, nil
} }
res, err := m.solanaClient.GetTransaction(event.RequestParams) // res, err := m.solanaClient.GetTransaction(event.RequestParams)
res, err := m.EventRequestType(event.RequestType, event.RequestParams)
if err != nil { if err != nil {
return nil, xerrors.Errorf("Couldn't get solana request: %w", err) return nil, xerrors.Errorf("Couldn't get solana request: %w", err)
} }
@ -150,3 +156,24 @@ func (m *Miner) computeTicket(ctx context.Context, brand *types.BeaconEntry) (*t
VRFProof: vrfOut, VRFProof: vrfOut,
}, nil }, nil
} }
func (m *Miner) EventRequestType(rType uint8, params string) ([]byte, error) {
switch rType {
case 1:
return m.filecoinClient.GetTransaction(params)
case 2:
return m.filecoinClient.GetBlock(params)
case 3:
i, err := strconv.ParseInt(params, 10, 64)
if err != nil {
return nil, xerrors.Errorf("Couldn't parse int from string request params: %w", err)
}
return m.filecoinClient.GetTipSetByHeight(i)
case 4:
return m.filecoinClient.GetChainHead()
case 5:
return m.filecoinClient.GetNodeVersion()
default:
return m.filecoinClient.GetTransaction(params)
}
}

View File

@ -27,7 +27,7 @@ var (
) )
// OracleEmitterABI is the input ABI used to generate the binding from. // OracleEmitterABI is the input ABI used to generate the binding from.
const OracleEmitterABI = "[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"originChain\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"requestType\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"requestParams\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"requestID\",\"type\":\"uint256\"}],\"name\":\"NewOracleRequest\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"originChain\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"requestType\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"requestParams\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"}],\"name\":\"requestOracles\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" const OracleEmitterABI = "[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"originChain\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"requestType\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"requestParams\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"requestID\",\"type\":\"uint256\"}],\"name\":\"NewOracleRequest\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"originChain\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"requestType\",\"type\":\"uint8\"},{\"internalType\":\"string\",\"name\":\"requestParams\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"}],\"name\":\"requestOracles\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
// OracleEmitter is an auto generated Go binding around an Ethereum contract. // OracleEmitter is an auto generated Go binding around an Ethereum contract.
type OracleEmitter struct { type OracleEmitter struct {
@ -171,24 +171,24 @@ func (_OracleEmitter *OracleEmitterTransactorRaw) Transact(opts *bind.TransactOp
return _OracleEmitter.Contract.contract.Transact(opts, method, params...) return _OracleEmitter.Contract.contract.Transact(opts, method, params...)
} }
// RequestOracles is a paid mutator transaction binding the contract method 0x8fe3d79f. // RequestOracles is a paid mutator transaction binding the contract method 0xa5bc5dfe.
// //
// Solidity: function requestOracles(string originChain, string requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID) returns(uint256) // Solidity: function requestOracles(uint8 originChain, uint8 requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID) returns(uint256)
func (_OracleEmitter *OracleEmitterTransactor) RequestOracles(opts *bind.TransactOpts, originChain string, requestType string, requestParams string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) { func (_OracleEmitter *OracleEmitterTransactor) RequestOracles(opts *bind.TransactOpts, originChain uint8, requestType uint8, requestParams string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) {
return _OracleEmitter.contract.Transact(opts, "requestOracles", originChain, requestType, requestParams, callbackAddress, callbackMethodID) return _OracleEmitter.contract.Transact(opts, "requestOracles", originChain, requestType, requestParams, callbackAddress, callbackMethodID)
} }
// RequestOracles is a paid mutator transaction binding the contract method 0x8fe3d79f. // RequestOracles is a paid mutator transaction binding the contract method 0xa5bc5dfe.
// //
// Solidity: function requestOracles(string originChain, string requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID) returns(uint256) // Solidity: function requestOracles(uint8 originChain, uint8 requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID) returns(uint256)
func (_OracleEmitter *OracleEmitterSession) RequestOracles(originChain string, requestType string, requestParams string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) { func (_OracleEmitter *OracleEmitterSession) RequestOracles(originChain uint8, requestType uint8, requestParams string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) {
return _OracleEmitter.Contract.RequestOracles(&_OracleEmitter.TransactOpts, originChain, requestType, requestParams, callbackAddress, callbackMethodID) return _OracleEmitter.Contract.RequestOracles(&_OracleEmitter.TransactOpts, originChain, requestType, requestParams, callbackAddress, callbackMethodID)
} }
// RequestOracles is a paid mutator transaction binding the contract method 0x8fe3d79f. // RequestOracles is a paid mutator transaction binding the contract method 0xa5bc5dfe.
// //
// Solidity: function requestOracles(string originChain, string requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID) returns(uint256) // Solidity: function requestOracles(uint8 originChain, uint8 requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID) returns(uint256)
func (_OracleEmitter *OracleEmitterTransactorSession) RequestOracles(originChain string, requestType string, requestParams string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) { func (_OracleEmitter *OracleEmitterTransactorSession) RequestOracles(originChain uint8, requestType uint8, requestParams string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) {
return _OracleEmitter.Contract.RequestOracles(&_OracleEmitter.TransactOpts, originChain, requestType, requestParams, callbackAddress, callbackMethodID) return _OracleEmitter.Contract.RequestOracles(&_OracleEmitter.TransactOpts, originChain, requestType, requestParams, callbackAddress, callbackMethodID)
} }
@ -261,8 +261,8 @@ func (it *OracleEmitterNewOracleRequestIterator) Close() error {
// OracleEmitterNewOracleRequest represents a NewOracleRequest event raised by the OracleEmitter contract. // OracleEmitterNewOracleRequest represents a NewOracleRequest event raised by the OracleEmitter contract.
type OracleEmitterNewOracleRequest struct { type OracleEmitterNewOracleRequest struct {
OriginChain string OriginChain uint8
RequestType string RequestType uint8
RequestParams string RequestParams string
CallbackAddress common.Address CallbackAddress common.Address
CallbackMethodID [4]byte CallbackMethodID [4]byte
@ -270,9 +270,9 @@ type OracleEmitterNewOracleRequest struct {
Raw types.Log // Blockchain specific contextual infos Raw types.Log // Blockchain specific contextual infos
} }
// FilterNewOracleRequest is a free log retrieval operation binding the contract event 0x4840d7d041230e7d05eaf9e64f0924379c740cd38ebe8ced4ca8b22afb8d3c94. // FilterNewOracleRequest is a free log retrieval operation binding the contract event 0xaa3cd18b7cba9d24d288b9b45616e263b5f40a939fe7f4341f789b955649ea4a.
// //
// Solidity: event NewOracleRequest(string originChain, string requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID, uint256 requestID) // Solidity: event NewOracleRequest(uint8 originChain, uint8 requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID, uint256 requestID)
func (_OracleEmitter *OracleEmitterFilterer) FilterNewOracleRequest(opts *bind.FilterOpts) (*OracleEmitterNewOracleRequestIterator, error) { func (_OracleEmitter *OracleEmitterFilterer) FilterNewOracleRequest(opts *bind.FilterOpts) (*OracleEmitterNewOracleRequestIterator, error) {
logs, sub, err := _OracleEmitter.contract.FilterLogs(opts, "NewOracleRequest") logs, sub, err := _OracleEmitter.contract.FilterLogs(opts, "NewOracleRequest")
@ -282,9 +282,9 @@ func (_OracleEmitter *OracleEmitterFilterer) FilterNewOracleRequest(opts *bind.F
return &OracleEmitterNewOracleRequestIterator{contract: _OracleEmitter.contract, event: "NewOracleRequest", logs: logs, sub: sub}, nil return &OracleEmitterNewOracleRequestIterator{contract: _OracleEmitter.contract, event: "NewOracleRequest", logs: logs, sub: sub}, nil
} }
// WatchNewOracleRequest is a free log subscription operation binding the contract event 0x4840d7d041230e7d05eaf9e64f0924379c740cd38ebe8ced4ca8b22afb8d3c94. // WatchNewOracleRequest is a free log subscription operation binding the contract event 0xaa3cd18b7cba9d24d288b9b45616e263b5f40a939fe7f4341f789b955649ea4a.
// //
// Solidity: event NewOracleRequest(string originChain, string requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID, uint256 requestID) // Solidity: event NewOracleRequest(uint8 originChain, uint8 requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID, uint256 requestID)
func (_OracleEmitter *OracleEmitterFilterer) WatchNewOracleRequest(opts *bind.WatchOpts, sink chan<- *OracleEmitterNewOracleRequest) (event.Subscription, error) { func (_OracleEmitter *OracleEmitterFilterer) WatchNewOracleRequest(opts *bind.WatchOpts, sink chan<- *OracleEmitterNewOracleRequest) (event.Subscription, error) {
logs, sub, err := _OracleEmitter.contract.WatchLogs(opts, "NewOracleRequest") logs, sub, err := _OracleEmitter.contract.WatchLogs(opts, "NewOracleRequest")
@ -319,9 +319,9 @@ func (_OracleEmitter *OracleEmitterFilterer) WatchNewOracleRequest(opts *bind.Wa
}), nil }), nil
} }
// ParseNewOracleRequest is a log parse operation binding the contract event 0x4840d7d041230e7d05eaf9e64f0924379c740cd38ebe8ced4ca8b22afb8d3c94. // ParseNewOracleRequest is a log parse operation binding the contract event 0xaa3cd18b7cba9d24d288b9b45616e263b5f40a939fe7f4341f789b955649ea4a.
// //
// Solidity: event NewOracleRequest(string originChain, string requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID, uint256 requestID) // Solidity: event NewOracleRequest(uint8 originChain, uint8 requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID, uint256 requestID)
func (_OracleEmitter *OracleEmitterFilterer) ParseNewOracleRequest(log types.Log) (*OracleEmitterNewOracleRequest, error) { func (_OracleEmitter *OracleEmitterFilterer) ParseNewOracleRequest(log types.Log) (*OracleEmitterNewOracleRequest, error) {
event := new(OracleEmitterNewOracleRequest) event := new(OracleEmitterNewOracleRequest)
if err := _OracleEmitter.contract.UnpackLog(event, "NewOracleRequest", log); err != nil { if err := _OracleEmitter.contract.UnpackLog(event, "NewOracleRequest", log); err != nil {

View File

@ -13,8 +13,12 @@ import (
httpClient "github.com/drand/drand/client/http" httpClient "github.com/drand/drand/client/http"
libp2pClient "github.com/drand/drand/lp2p/client" libp2pClient "github.com/drand/drand/lp2p/client"
"github.com/drand/kyber" "github.com/drand/kyber"
logging "github.com/ipfs/go-log"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"go.uber.org/zap/zapcore"
dlog "github.com/drand/drand/log"
kzap "github.com/go-kit/kit/log/zap"
pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/Secured-Finance/dione/config" "github.com/Secured-Finance/dione/config"
@ -22,6 +26,8 @@ import (
types "github.com/Secured-Finance/dione/types" types "github.com/Secured-Finance/dione/types"
) )
var log = logging.Logger("drand")
// DrandRes structure representing response from drand network // DrandRes structure representing response from drand network
type DrandRes struct { type DrandRes struct {
// PreviousSig is the previous signature generated // PreviousSig is the previous signature generated
@ -54,6 +60,9 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub) (*DrandBeacon
return nil, fmt.Errorf("unable to unmarshal drand chain info: %w", err) return nil, fmt.Errorf("unable to unmarshal drand chain info: %w", err)
} }
dlogger := dlog.NewKitLoggerFrom(kzap.NewZapSugarLogger(
log.SugaredLogger.Desugar(), zapcore.InfoLevel))
var clients []client.Client var clients []client.Client
for _, url := range cfg.Servers { for _, url := range cfg.Servers {
client, err := httpClient.NewWithInfo(url, drandChain, nil) client, err := httpClient.NewWithInfo(url, drandChain, nil)
@ -67,6 +76,7 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub) (*DrandBeacon
client.WithChainInfo(drandChain), client.WithChainInfo(drandChain),
client.WithCacheSize(1024), client.WithCacheSize(1024),
client.WithAutoWatch(), client.WithAutoWatch(),
client.WithLogger(dlogger),
} }
if ps != nil { if ps != nil {

View File

@ -18,7 +18,7 @@ contract Mediator is Ownable {
aggregator = _aggregator; aggregator = _aggregator;
} }
function request(string memory originChain, string memory requestType, string memory requestParams) public returns (uint256) { function request(uint8 originChain, uint8 requestType, string memory requestParams) public returns (uint256) {
return oracleEmitter.requestOracles(originChain, requestType, requestParams, address(this), bytes4(keccak256("_receiveDataCallback(uint256, string)"))); return oracleEmitter.requestOracles(originChain, requestType, requestParams, address(this), bytes4(keccak256("_receiveDataCallback(uint256, string)")));
} }

View File

@ -5,15 +5,15 @@ contract OracleEmitter {
uint256 requestCounter; uint256 requestCounter;
event NewOracleRequest( event NewOracleRequest(
string originChain, uint8 originChain,
string requestType, uint8 requestType,
string requestParams, string requestParams,
address callbackAddress, address callbackAddress,
bytes4 callbackMethodID, bytes4 callbackMethodID,
uint256 requestID uint256 requestID
); );
function requestOracles(string memory originChain, string memory requestType, string memory requestParams, address callbackAddress, bytes4 callbackMethodID) public returns (uint256) { function requestOracles(uint8 originChain, uint8 requestType, string memory requestParams, address callbackAddress, bytes4 callbackMethodID) public returns (uint256) {
requestCounter++; requestCounter++;
emit NewOracleRequest(originChain, requestType, requestParams, callbackAddress, callbackMethodID, requestCounter); emit NewOracleRequest(originChain, requestType, requestParams, callbackAddress, callbackMethodID, requestCounter);
return requestCounter; return requestCounter;

3
go.mod
View File

@ -20,6 +20,7 @@ require (
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect
github.com/fxamacker/cbor/v2 v2.2.0 github.com/fxamacker/cbor/v2 v2.2.0
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
github.com/go-kit/kit v0.10.0
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
github.com/gobwas/ws v1.0.4 // indirect github.com/gobwas/ws v1.0.4 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
@ -30,6 +31,7 @@ require (
github.com/ipfs/go-ds-badger2 v0.1.1-0.20200708190120-187fc06f714e // indirect github.com/ipfs/go-ds-badger2 v0.1.1-0.20200708190120-187fc06f714e // indirect
github.com/ipfs/go-ipld-cbor v0.0.5-0.20200428170625-a0bd04d3cbdf // indirect github.com/ipfs/go-ipld-cbor v0.0.5-0.20200428170625-a0bd04d3cbdf // indirect
github.com/ipfs/go-ipld-format v0.2.0 // indirect github.com/ipfs/go-ipld-format v0.2.0 // indirect
github.com/ipfs/go-log v1.0.4
github.com/ipfs/go-log/v2 v2.1.2-0.20200626104915-0016c0b4b3e4 // indirect github.com/ipfs/go-log/v2 v2.1.2-0.20200626104915-0016c0b4b3e4 // indirect
github.com/jmoiron/sqlx v1.2.0 github.com/jmoiron/sqlx v1.2.0
github.com/karalabe/usb v0.0.0-20191104083709-911d15fe12a9 // indirect github.com/karalabe/usb v0.0.0-20191104083709-911d15fe12a9 // indirect
@ -64,6 +66,7 @@ require (
github.com/whyrusleeping/cbor-gen v0.0.0-20200826160007-0b9f6c5fb163 github.com/whyrusleeping/cbor-gen v0.0.0-20200826160007-0b9f6c5fb163
github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208 // indirect github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208 // indirect
github.com/xorcare/golden v0.6.1-0.20191112154924-b87f686d7542 github.com/xorcare/golden v0.6.1-0.20191112154924-b87f686d7542
go.uber.org/zap v1.15.0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/tools v0.0.0-20200827010519-17fd2f27a9e3 // indirect golang.org/x/tools v0.0.0-20200827010519-17fd2f27a9e3 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1

View File

@ -27,19 +27,6 @@ func (n *Node) subscribeOnEthContracts(ctx context.Context) {
} }
logrus.Info("BlockHash for Solana transaction: ", task.BlockHash) logrus.Info("BlockHash for Solana transaction: ", task.BlockHash)
logrus.Info("Started new consensus round with ID: ", task.BlockHash) logrus.Info("Started new consensus round with ID: ", task.BlockHash)
//n.ConsensusManager.NewTestConsensus(string(task.BlockHash), task.BlockHash, func(finalData string) {
// if finalData != string(task.BlockHash) {
// logrus.Warnf("Expected final data to be %s, not %s", task.BlockHash, finalData)
// return
// }
// logrus.Info("Consensus ID: ", task.BlockHash, " was successfull")
// logrus.Info("Submitting on-chain result: ", task.BlockHash, "for consensus ID: ", task.BlockHash)
// if task.Miner == n.Host.ID() {
// if err := n.Ethereum.SubmitRequestAnswer(event.RequestID, task.BlockHash, event.CallbackAddress, event.CallbackMethodID); err != nil {
// logrus.Warn("Can't submit request to ethereum chain: ", err)
// }
// }
//})
err = n.ConsensusManager.Propose(event.RequestID.String(), task.BlockHash, event.RequestID, event.CallbackAddress) err = n.ConsensusManager.Propose(event.RequestID.String(), task.BlockHash, event.RequestID, event.CallbackAddress)
if err != nil { if err != nil {

View File

@ -96,7 +96,7 @@ func (n *Node) setupNode(ctx context.Context, prvKey crypto.PrivKey, pexDiscover
} }
func (n *Node) setupMiner() error { func (n *Node) setupMiner() error {
n.Miner = consensus.NewMiner(n.Host.ID(), *n.Ethereum.GetEthAddress(), n.Wallet, n.Beacon, n.Ethereum, n.Solana) n.Miner = consensus.NewMiner(n.Host.ID(), *n.Ethereum.GetEthAddress(), n.Wallet, n.Beacon, n.Ethereum, n.Lotus, n.Solana)
return nil return nil
} }
@ -143,7 +143,7 @@ func (n *Node) setupEthereumClient() error {
} }
func (n *Node) setupFilecoinClient() { func (n *Node) setupFilecoinClient() {
lotus := filecoin.NewLotusClient(n.Config.Filecoin.LotusHost, n.Config.Filecoin.LotusToken) lotus := filecoin.NewLotusClient()
n.Lotus = lotus n.Lotus = lotus
} }

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"math/rand" "math/rand"
"sync"
"testing" "testing"
"time" "time"
@ -16,7 +15,7 @@ func TestConsensus(t *testing.T) {
logrus.SetLevel(logrus.DebugLevel) logrus.SetLevel(logrus.DebugLevel)
//log.SetAllLoggers(log.LevelDebug) //log.SetAllLoggers(log.LevelDebug)
boolgen := newBoolgen() // boolgen := newBoolgen()
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
port := rand.Intn(100) + 10000 port := rand.Intn(100) + 10000
@ -47,24 +46,24 @@ func TestConsensus(t *testing.T) {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
var wg sync.WaitGroup // var wg sync.WaitGroup
wg.Add(len(nodes)) // wg.Add(len(nodes))
for _, n := range nodes { // for _, n := range nodes {
var testData string // var testData string
if boolgen.Bool() { // if boolgen.Bool() {
testData = "test" // testData = "test"
} else { // } else {
testData = "test1" // testData = "test1"
} // }
n.ConsensusManager.NewTestConsensus(testData, "123", func(finalData string) { // n.ConsensusManager.NewTestConsensus(testData, "123", func(finalData string) {
if finalData != "test" { // if finalData != "test" {
t.Errorf("Expected final data %s, not %s", "test", finalData) // t.Errorf("Expected final data %s, not %s", "test", finalData)
} // }
wg.Done() // wg.Done()
}) // })
} // }
wg.Wait() // wg.Wait()
} }
func newNode(cfg *config.Config) *Node { func newNode(cfg *config.Config) *Node {

View File

@ -4,39 +4,66 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
ftypes "github.com/Secured-Finance/dione/rpc/filecoin/types"
"github.com/Secured-Finance/dione/rpc/types" "github.com/Secured-Finance/dione/rpc/types"
"github.com/Secured-Finance/dione/lib"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
) )
var filecoinURL = "https://filecoin.infura.io/" var filecoinURL = "https://api.node.glif.io/"
// client implements the `Client` interface.
type LotusClient struct { type LotusClient struct {
host string host string
projectID string httpClient *fasthttp.Client
projectSecret string
httpClient *fasthttp.Client
} }
func NewLotusClient(pID, secret string) *LotusClient { // NewClient returns a new client.
func NewLotusClient() *LotusClient {
return &LotusClient{ return &LotusClient{
host: filecoinURL, host: filecoinURL,
projectID: pID, httpClient: &fasthttp.Client{},
projectSecret: secret,
httpClient: &fasthttp.Client{},
} }
} }
func (c *LotusClient) GetTransaction(txHash string) ([]byte, error) { func (c *LotusClient) GetBlock(cid string) ([]byte, error) {
i := ftypes.NewCidParam(cid)
return c.HandleRequest("Filecoin.ChainGetBlock", i)
}
func (c *LotusClient) GetTipSetByHeight(chainEpoch int64) ([]byte, error) {
i := make([]interface{}, 0)
i = append(i, chainEpoch, nil)
return c.HandleRequest("Filecoin.ChainGetTipSetByHeight", i)
}
func (c *LotusClient) GetTransaction(cid string) ([]byte, error) {
i := ftypes.NewCidParam(cid)
return c.HandleRequest("Filecoin.ChainGetMessage", i)
}
func (c *LotusClient) GetNodeVersion() ([]byte, error) {
return c.HandleRequest("Filecoin.Version", nil)
}
func (c *LotusClient) GetChainHead() ([]byte, error) {
return c.HandleRequest("Filecoin.ChainHead", nil)
}
func (c *LotusClient) VerifyCid(cid string) ([]byte, error) {
i := ftypes.NewCidParam(cid)
return c.HandleRequest("Filecoin.ChainHasObj", i)
}
// HandleRequest implements the `Client` interface.
func (c *LotusClient) HandleRequest(method string, params []interface{}) ([]byte, error) {
req := fasthttp.AcquireRequest() req := fasthttp.AcquireRequest()
req.SetRequestURI(c.host) req.SetRequestURI(c.host)
req.Header.SetMethod("POST") req.Header.SetMethod("POST")
req.Header.SetContentType("application/json") req.Header.SetContentType("application/json")
req.Header.Set("Authorization", "Basic "+lib.BasicAuth(c.projectID, c.projectSecret)) requestBody := types.NewRPCRequestBody(method)
requestBody := types.NewRPCRequestBody("Filecoin.ChainGetMessage") requestBody.Params = append(requestBody.Params, params...)
requestBody.Params = append(requestBody.Params, txHash)
body, err := json.Marshal(requestBody) body, err := json.Marshal(requestBody)
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed to marshal request body %v", err) return nil, fmt.Errorf("Failed to marshal request body %v", err)
@ -48,6 +75,6 @@ func (c *LotusClient) GetTransaction(txHash string) ([]byte, error) {
return nil, err return nil, err
} }
bodyBytes := resp.Body() bodyBytes := resp.Body()
logrus.Debug(string(bodyBytes)) logrus.Info(string(bodyBytes))
return bodyBytes, nil return bodyBytes, nil
} }

View File

@ -0,0 +1,14 @@
package types
type FilParams struct {
Cid interface{} `json:"/"`
}
func NewCidParam(cid interface{}) []interface{} {
i := make([]interface{}, 0)
p := &FilParams{
Cid: cid,
}
i = append(i, p)
return i
}

View File

@ -8,7 +8,7 @@ type RPCRequestBody struct {
} }
func NewRPCRequestBody(method string) *RPCRequestBody { func NewRPCRequestBody(method string) *RPCRequestBody {
var i []interface{} i := make([]interface{}, 0)
return &RPCRequestBody{ return &RPCRequestBody{
Jsonrpc: "2.0", Jsonrpc: "2.0",
Method: method, Method: method,