add: filecoin api schema, eth-contracts types changes
This commit is contained in:
parent
b2e956d1d4
commit
52ec8dbd35
@ -3,8 +3,10 @@ package consensus
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
fil "github.com/Secured-Finance/dione/rpc/filecoin"
|
||||
solana2 "github.com/Secured-Finance/dione/rpc/solana"
|
||||
|
||||
"github.com/Secured-Finance/dione/beacon"
|
||||
@ -27,6 +29,7 @@ type Miner struct {
|
||||
mutex sync.Mutex
|
||||
beacon beacon.BeaconNetworks
|
||||
ethClient *ethclient.EthereumClient
|
||||
filecoinClient *fil.LotusClient
|
||||
solanaClient *solana2.SolanaClient
|
||||
minerStake types.BigInt
|
||||
networkStake types.BigInt
|
||||
@ -38,6 +41,7 @@ func NewMiner(
|
||||
api WalletAPI,
|
||||
beacon beacon.BeaconNetworks,
|
||||
ethClient *ethclient.EthereumClient,
|
||||
filecoinClient *fil.LotusClient,
|
||||
solanaClient *solana2.SolanaClient,
|
||||
) *Miner {
|
||||
return &Miner{
|
||||
@ -46,6 +50,7 @@ func NewMiner(
|
||||
api: api,
|
||||
beacon: beacon,
|
||||
ethClient: ethClient,
|
||||
filecoinClient: filecoinClient,
|
||||
solanaClient: solanaClient,
|
||||
}
|
||||
}
|
||||
@ -102,7 +107,8 @@ func (m *Miner) MineTask(ctx context.Context, event *oracleEmitter.OracleEmitter
|
||||
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 {
|
||||
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,
|
||||
}, 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)
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ var (
|
||||
)
|
||||
|
||||
// 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.
|
||||
type OracleEmitter struct {
|
||||
@ -171,24 +171,24 @@ func (_OracleEmitter *OracleEmitterTransactorRaw) Transact(opts *bind.TransactOp
|
||||
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)
|
||||
func (_OracleEmitter *OracleEmitterTransactor) RequestOracles(opts *bind.TransactOpts, originChain string, requestType string, requestParams string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) {
|
||||
// Solidity: function requestOracles(uint8 originChain, uint8 requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID) returns(uint256)
|
||||
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)
|
||||
}
|
||||
|
||||
// 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)
|
||||
func (_OracleEmitter *OracleEmitterSession) RequestOracles(originChain string, requestType string, requestParams string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) {
|
||||
// Solidity: function requestOracles(uint8 originChain, uint8 requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID) returns(uint256)
|
||||
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)
|
||||
}
|
||||
|
||||
// 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)
|
||||
func (_OracleEmitter *OracleEmitterTransactorSession) RequestOracles(originChain string, requestType string, requestParams string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) {
|
||||
// Solidity: function requestOracles(uint8 originChain, uint8 requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID) returns(uint256)
|
||||
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)
|
||||
}
|
||||
|
||||
@ -261,8 +261,8 @@ func (it *OracleEmitterNewOracleRequestIterator) Close() error {
|
||||
|
||||
// OracleEmitterNewOracleRequest represents a NewOracleRequest event raised by the OracleEmitter contract.
|
||||
type OracleEmitterNewOracleRequest struct {
|
||||
OriginChain string
|
||||
RequestType string
|
||||
OriginChain uint8
|
||||
RequestType uint8
|
||||
RequestParams string
|
||||
CallbackAddress common.Address
|
||||
CallbackMethodID [4]byte
|
||||
@ -270,9 +270,9 @@ type OracleEmitterNewOracleRequest struct {
|
||||
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) {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
logs, sub, err := _OracleEmitter.contract.WatchLogs(opts, "NewOracleRequest")
|
||||
@ -319,9 +319,9 @@ func (_OracleEmitter *OracleEmitterFilterer) WatchNewOracleRequest(opts *bind.Wa
|
||||
}), 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) {
|
||||
event := new(OracleEmitterNewOracleRequest)
|
||||
if err := _OracleEmitter.contract.UnpackLog(event, "NewOracleRequest", log); err != nil {
|
||||
|
@ -13,8 +13,12 @@ import (
|
||||
httpClient "github.com/drand/drand/client/http"
|
||||
libp2pClient "github.com/drand/drand/lp2p/client"
|
||||
"github.com/drand/kyber"
|
||||
logging "github.com/ipfs/go-log"
|
||||
"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"
|
||||
|
||||
"github.com/Secured-Finance/dione/config"
|
||||
@ -22,6 +26,8 @@ import (
|
||||
types "github.com/Secured-Finance/dione/types"
|
||||
)
|
||||
|
||||
var log = logging.Logger("drand")
|
||||
|
||||
// DrandRes structure representing response from drand network
|
||||
type DrandRes struct {
|
||||
// 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)
|
||||
}
|
||||
|
||||
dlogger := dlog.NewKitLoggerFrom(kzap.NewZapSugarLogger(
|
||||
log.SugaredLogger.Desugar(), zapcore.InfoLevel))
|
||||
|
||||
var clients []client.Client
|
||||
for _, url := range cfg.Servers {
|
||||
client, err := httpClient.NewWithInfo(url, drandChain, nil)
|
||||
@ -67,6 +76,7 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub) (*DrandBeacon
|
||||
client.WithChainInfo(drandChain),
|
||||
client.WithCacheSize(1024),
|
||||
client.WithAutoWatch(),
|
||||
client.WithLogger(dlogger),
|
||||
}
|
||||
|
||||
if ps != nil {
|
||||
|
@ -18,7 +18,7 @@ contract Mediator is Ownable {
|
||||
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)")));
|
||||
}
|
||||
|
||||
|
@ -5,15 +5,15 @@ contract OracleEmitter {
|
||||
uint256 requestCounter;
|
||||
|
||||
event NewOracleRequest(
|
||||
string originChain,
|
||||
string requestType,
|
||||
uint8 originChain,
|
||||
uint8 requestType,
|
||||
string requestParams,
|
||||
address callbackAddress,
|
||||
bytes4 callbackMethodID,
|
||||
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++;
|
||||
emit NewOracleRequest(originChain, requestType, requestParams, callbackAddress, callbackMethodID, requestCounter);
|
||||
return requestCounter;
|
||||
|
3
go.mod
3
go.mod
@ -20,6 +20,7 @@ require (
|
||||
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect
|
||||
github.com/fxamacker/cbor/v2 v2.2.0
|
||||
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/gobwas/ws v1.0.4 // 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-ipld-cbor v0.0.5-0.20200428170625-a0bd04d3cbdf // 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/jmoiron/sqlx v1.2.0
|
||||
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/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208 // indirect
|
||||
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/tools v0.0.0-20200827010519-17fd2f27a9e3 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
|
||||
|
@ -27,19 +27,6 @@ func (n *Node) subscribeOnEthContracts(ctx context.Context) {
|
||||
}
|
||||
logrus.Info("BlockHash for Solana transaction: ", 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)
|
||||
if err != nil {
|
||||
|
@ -96,7 +96,7 @@ func (n *Node) setupNode(ctx context.Context, prvKey crypto.PrivKey, pexDiscover
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ func (n *Node) setupEthereumClient() error {
|
||||
}
|
||||
|
||||
func (n *Node) setupFilecoinClient() {
|
||||
lotus := filecoin.NewLotusClient(n.Config.Filecoin.LotusHost, n.Config.Filecoin.LotusToken)
|
||||
lotus := filecoin.NewLotusClient()
|
||||
n.Lotus = lotus
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -16,7 +15,7 @@ func TestConsensus(t *testing.T) {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
//log.SetAllLoggers(log.LevelDebug)
|
||||
|
||||
boolgen := newBoolgen()
|
||||
// boolgen := newBoolgen()
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
port := rand.Intn(100) + 10000
|
||||
|
||||
@ -47,24 +46,24 @@ func TestConsensus(t *testing.T) {
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
// var wg sync.WaitGroup
|
||||
|
||||
wg.Add(len(nodes))
|
||||
for _, n := range nodes {
|
||||
var testData string
|
||||
if boolgen.Bool() {
|
||||
testData = "test"
|
||||
} else {
|
||||
testData = "test1"
|
||||
}
|
||||
n.ConsensusManager.NewTestConsensus(testData, "123", func(finalData string) {
|
||||
if finalData != "test" {
|
||||
t.Errorf("Expected final data %s, not %s", "test", finalData)
|
||||
}
|
||||
wg.Done()
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
// wg.Add(len(nodes))
|
||||
// for _, n := range nodes {
|
||||
// var testData string
|
||||
// if boolgen.Bool() {
|
||||
// testData = "test"
|
||||
// } else {
|
||||
// testData = "test1"
|
||||
// }
|
||||
// n.ConsensusManager.NewTestConsensus(testData, "123", func(finalData string) {
|
||||
// if finalData != "test" {
|
||||
// t.Errorf("Expected final data %s, not %s", "test", finalData)
|
||||
// }
|
||||
// wg.Done()
|
||||
// })
|
||||
// }
|
||||
// wg.Wait()
|
||||
}
|
||||
|
||||
func newNode(cfg *config.Config) *Node {
|
||||
|
@ -4,39 +4,66 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
ftypes "github.com/Secured-Finance/dione/rpc/filecoin/types"
|
||||
"github.com/Secured-Finance/dione/rpc/types"
|
||||
|
||||
"github.com/Secured-Finance/dione/lib"
|
||||
"github.com/sirupsen/logrus"
|
||||
"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 {
|
||||
host string
|
||||
projectID string
|
||||
projectSecret string
|
||||
httpClient *fasthttp.Client
|
||||
}
|
||||
|
||||
func NewLotusClient(pID, secret string) *LotusClient {
|
||||
// NewClient returns a new client.
|
||||
func NewLotusClient() *LotusClient {
|
||||
return &LotusClient{
|
||||
host: filecoinURL,
|
||||
projectID: pID,
|
||||
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.SetRequestURI(c.host)
|
||||
req.Header.SetMethod("POST")
|
||||
req.Header.SetContentType("application/json")
|
||||
req.Header.Set("Authorization", "Basic "+lib.BasicAuth(c.projectID, c.projectSecret))
|
||||
requestBody := types.NewRPCRequestBody("Filecoin.ChainGetMessage")
|
||||
requestBody.Params = append(requestBody.Params, txHash)
|
||||
requestBody := types.NewRPCRequestBody(method)
|
||||
requestBody.Params = append(requestBody.Params, params...)
|
||||
body, err := json.Marshal(requestBody)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
bodyBytes := resp.Body()
|
||||
logrus.Debug(string(bodyBytes))
|
||||
logrus.Info(string(bodyBytes))
|
||||
return bodyBytes, nil
|
||||
}
|
||||
|
14
rpc/filecoin/types/params.go
Normal file
14
rpc/filecoin/types/params.go
Normal 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
|
||||
}
|
@ -8,7 +8,7 @@ type RPCRequestBody struct {
|
||||
}
|
||||
|
||||
func NewRPCRequestBody(method string) *RPCRequestBody {
|
||||
var i []interface{}
|
||||
i := make([]interface{}, 0)
|
||||
return &RPCRequestBody{
|
||||
Jsonrpc: "2.0",
|
||||
Method: method,
|
||||
|
Loading…
Reference in New Issue
Block a user