diff --git a/config/config.go b/config/config.go index 8b83821..a5b1a9e 100644 --- a/config/config.go +++ b/config/config.go @@ -14,6 +14,7 @@ type Config struct { Rendezvous string `toml:"rendezvous"` ProtocolID string `toml:"protocol_id"` SessionKey string `toml:"session_key"` + PrivateKey string `toml:"private_key"` } // viperEnvVariable loads config parameters from .env file @@ -58,6 +59,7 @@ func NewConfig() *Config { Rendezvous := viperEnvString("RENDEZVOUS", "filecoin-p2p-oracle") ProtocolID := viperEnvString("PROTOCOL_ID", "p2p-oracle") SessionKey := viperEnvString("SESSION_KEY", "go") + PrivateKey := viperEnvString("PRIVATE_KEY", "") return &Config{ ListenPort: ListenPort, @@ -67,5 +69,6 @@ func NewConfig() *Config { Rendezvous: Rendezvous, ProtocolID: ProtocolID, SessionKey: SessionKey, + PrivateKey: PrivateKey, } } diff --git a/handler/handler.go b/handler/handler.go index 3f1e72f..42d55a0 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -36,6 +36,8 @@ func NewHandler(pb *pubsub.PubSub, oracleTopic string, peerID peer.ID, networkTo identityMap: make(map[peer.ID]string), Logger: log.Logger("rendezvous"), } + log.SetAllLoggers(log.LevelInfo) + return handler } diff --git a/node/node.go b/node/node.go index 797d244..6d25387 100644 --- a/node/node.go +++ b/node/node.go @@ -34,6 +34,7 @@ func NewNode() *Node { Logger: log.Logger("rendezvous"), networkTopics: mapset.NewSet(), } + log.SetAllLoggers(log.LevelInfo) return node } diff --git a/rpcclient/ethereum.go b/rpcclient/ethereum.go index 46c02c4..94f241b 100644 --- a/rpcclient/ethereum.go +++ b/rpcclient/ethereum.go @@ -5,9 +5,12 @@ import ( "crypto/ecdsa" "io/ioutil" "math/big" + "strings" "github.com/Secured-Finance/p2p-oracle-node/contracts/aggregator" + "github.com/Secured-Finance/p2p-oracle-node/contracts/oracleemitter" "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/common" @@ -24,6 +27,13 @@ type EthereumClient struct { Logger *log.ZapEventLogger } +type OracleEvent struct { + RequestType string + CallbackAddress common.Address + CallbackMethodID [4]byte + RequestID *big.Int +} + type Ethereum interface { Connect(context.Context, string) error Balance(context.Context, string) (*big.Int, error) @@ -38,6 +48,7 @@ func NewEthereumClient() *EthereumClient { ethereumClient := &EthereumClient{ Logger: log.Logger("rendezvous"), } + log.SetAllLoggers(log.LevelInfo) return ethereumClient } @@ -136,12 +147,18 @@ func (c *EthereumClient) GenerateAddressFromPrivateKey(private_key string) strin return address } -func (c *EthereumClient) SubscribeOnSmartContractEvents(ctx context.Context, address string) { +func (c *EthereumClient) SubscribeOnOracleEvents(ctx context.Context, address string) { contractAddress := common.HexToAddress(address) + query := ethereum.FilterQuery{ Addresses: []common.Address{contractAddress}, } + contractAbi, err := abi.JSON(strings.NewReader(string(oracleemitter.SmartcontractsABI))) + if err != nil { + c.Logger.Fatal(err) + } + logs := make(chan types.Log) sub, err := c.WsClient.SubscribeFilterLogs(context.Background(), query, logs) if err != nil { @@ -153,10 +170,15 @@ func (c *EthereumClient) SubscribeOnSmartContractEvents(ctx context.Context, add case err := <-sub.Err(): c.Logger.Fatal(err) case vLog := <-logs: - c.Logger.Info(vLog) // pointer to event log + var event OracleEvent + err := contractAbi.Unpack(&event, "NewOracleRequest", vLog.Data) + + if err != nil { + c.Logger.Fatal(err) + } + c.Logger.Info(event) // pointer to event log } } - } func (c *EthereumClient) createKeyStore(password string) string {