Links

Filecoin Filrep Oracle: Obtain miner reputations on-chain

Midpoint

$ midpoint init filecoin-filrep-oracle filecoin-filrep
$ cd filecoin-filrep && midpoint publish

Contract

This template will interact with a sample contract deployed on Filecoin's Hyperspace Testnet. The contract is listed below. The address of this contract is:
0x83986ff4fbcaa2acf6092930fcebbe25583be452
// SPDX-License-Identifier: MIT
// This is a test contract deployed by Midpoint for demonstrating
pragma solidity>=0.8.0;
interface IMidpoint {
function callMidpoint(uint64 midpointId) external returns(uint64 requestId);
function callMidpoint(uint64 midpointId, bytes calldata _data) external returns(uint64 requestId);
}
address constant startpointAddress = 0x0705c34AA032354A7966776098E0c12cc5539Bc8;
address constant midpointCallbackAddress = 0xC0FFEE4a3A2D488B138d090b8112875B90b5e6D9;
contract MidpointOracleTestContract {
event ResultReturned(uint64 midpointId);
event ResultReturnedBool(uint64 midpointId, bool response);
event ResultReturnedI16(uint64 midpointId, int16 response);
event ResultReturnedI256(uint64 midpointId, int256 response);
event ResultReturnedU16(uint64 midpointId, uint16 response);
event ResultReturnedU256(uint64 midpointId, uint256 response);
event ResultReturnedAddr(uint64 midpointId, address response);
event ResultReturnedStr(uint64 midpointId, string response);
event ResultReturnedBoolArr(uint64 midpointId, bool[] response);
event ResultReturnedI16Arr(uint64 midpointId, int16[] response);
event ResultReturnedI256Arr(uint64 midpointId, int256[] response);
event ResultReturnedU16Arr(uint64 midpointId, uint16[] response);
event ResultReturnedU256Arr(uint64 midpointId, uint256[] response);
event ResultReturnedAddrArr(uint64 midpointId, address[] response);
event ResultReturnedStrArr(uint64 midpointId, string[] response);
event ResultReturnedU256U256(uint64 midpointId, uint256 response1, uint256 response2);
event ResultReturnedU256Str(uint64 midpointId, uint256 response1, string response2);
event ResultReturnedStrStr(uint64 midpointId, string response1, string response2);
event ResultReturnedU256U256U256(uint64 midpointId, uint256 response1, uint256 response2, uint256 response3);
event ResultReturnedU256U256Str(uint64 midpointId, uint256 response1, uint256 response2, string response3);
event ResultReturnedU256StrStr(uint64 midpointId, uint256 response1, string response2, string response3);
event ResultReturnedStrStrStr(uint64 midpointId, string response1, string response2, string response3);
function testCallToMidpoint(uint64 midpointId) public {
IMidpoint(startpointAddress).callMidpoint(midpointId);
}
function testCallToMidpoint(uint64 midpointId, bool var1) public {
bytes memory args = abi.encodePacked(var1);
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, uint16 var1) public {
bytes memory args = abi.encodePacked(var1);
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, uint256 var1) public {
bytes memory args = abi.encodePacked(var1);
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, int16 var1) public {
bytes memory args = abi.encodePacked(var1);
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, int256 var1) public {
bytes memory args = abi.encodePacked(var1);
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, address var1) public {
bytes memory args = abi.encodePacked(var1);
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, string calldata var1) public {
bytes memory args = abi.encodePacked(var1, bytes1(0x00));
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, bool var1, bool var2) public {
bytes memory args = abi.encodePacked(var1, var2);
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, uint16 var1, uint16 var2) public {
bytes memory args = abi.encodePacked(var1, var2);
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, int16 var1, uint16 var2) public {
bytes memory args = abi.encodePacked(var1, var2);
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, uint256 var1, int256 var2) public {
bytes memory args = abi.encodePacked(var1, var2);
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, int256 var1, int256 var2) public {
bytes memory args = abi.encodePacked(var1, var2);
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, address var1, address var2) public {
bytes memory args = abi.encodePacked(var1, var2);
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, string calldata var1, string calldata var2) public {
bytes memory args = abi.encodePacked(var1, bytes1(0x00), var2, bytes1(0x00));
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, bool var1, string calldata var2) public {
bytes memory args = abi.encodePacked(var1, var2, bytes1(0x00));
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, int16 var1, string calldata var2) public {
bytes memory args = abi.encodePacked(var1, var2, bytes1(0x00));
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, int256 var1, string calldata var2) public {
bytes memory args = abi.encodePacked(var1, var2, bytes1(0x00));
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, uint16 var1, string calldata var2) public {
bytes memory args = abi.encodePacked(var1, var2, bytes1(0x00));
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, uint256 var1, string calldata var2) public {
bytes memory args = abi.encodePacked(var1, var2, bytes1(0x00));
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, address var1, string calldata var2) public {
bytes memory args = abi.encodePacked(var1, var2, bytes1(0x00));
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function testCallToMidpoint(uint64 midpointId, string calldata var1, string calldata var2, string calldata var3) public {
bytes memory args = abi.encodePacked(var1, bytes1(0x00), var2, bytes1(0x00), var3, bytes1(0x00));
IMidpoint(startpointAddress).callMidpoint(midpointId, args);
}
function callback(uint64 midpointId) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturned(midpointId);
}
function callback(uint64 midpointId, bool response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedBool(midpointId, response);
}
function callback(uint64 midpointId, int16 response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedI16(midpointId, response);
}
function callback(uint64 midpointId, int256 response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedI256(midpointId, response);
}
function callback(uint64 midpointId, uint16 response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedU16(midpointId, response);
}
function callback(uint64 midpointId, uint256 response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedU256(midpointId, response);
}
function callback(uint64 midpointId, address response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedAddr(midpointId, response);
}
function callback(uint64 midpointId, string calldata response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedStr(midpointId, response);
}
function callback(uint64 midpointId, bool[] calldata response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedBoolArr(midpointId, response);
}
function callback(uint64 midpointId, int16[] calldata response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedI16Arr(midpointId, response);
}
function callback(uint64 midpointId, int256[] calldata response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedI256Arr(midpointId, response);
}
function callback(uint64 midpointId, uint16[] calldata response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedU16Arr(midpointId, response);
}
function callback(uint64 midpointId, uint256[] calldata response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedU256Arr(midpointId, response);
}
function callback(uint64 midpointId, address[] calldata response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedAddrArr(midpointId, response);
}
function callback(uint64 midpointId, string[] calldata response) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedStrArr(midpointId, response);
}
function callback(uint64 midpointId, uint256 response1, uint256 response2) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedU256U256(midpointId, response1, response2);
}
function callback(uint64 midpointId, uint256 response1, string calldata response2) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedU256Str(midpointId, response1, response2);
}
function callback(uint64 midpointId, string calldata response1, string calldata response2) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedStrStr(midpointId, response1, response2);
}
function callback(uint64 midpointId, uint256 response1, uint256 response2, uint256 response3) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedU256U256U256(midpointId, response1, response2, response3);
}
function callback(uint64 midpointId, uint256 response1, uint256 response2, string calldata response3) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedU256U256Str(midpointId, response1, response2, response3);
}
function callback(uint64 midpointId, uint256 response1, string calldata response2, string calldata response3) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedU256StrStr(midpointId, response1, response2, response3);
}
function callback(uint64 midpointId, string calldata response1, string calldata response2, string calldata response3) public {
require(tx.origin == midpointCallbackAddress, "Invalid EOA");
emit ResultReturnedStrStrStr(midpointId, response1, response2, response3);
}
}
Interacting With The Contract
The easiest way to interact with this contract is to deploy it on remix. Once you open remix, create a new contract and paste the contract's code from above.
The pasted contract
Once you create the contract, you should compile it.
Compiling the contract creates the ABI of your contract in remix. Now that this contract is compiled, you can connect to the contract with your contract's ABI and interact with it. Make sure "MidpointOracleTestContract" is selected, enter 0x83986ff4fbcaa2acf6092930fcebbe25583be452 as your contract address, and click "At Address".
That should be it -- just find the testCallToMidpoint function and enter your midpoint id in midpointId, and the id of a miner (e.g. f01040469) in var1, to test your midpoint!
For miner f01040469 you can look at this transaction to confirm that "97" was returned on-chain. The hexadecimal 0239370 converts to 97. You can modify the midpoint to return any solidity type instead of a string.
ABI
The ABI of the contract is below.
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
}
],
"name": "ResultReturned",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "address",
"name": "response",
"type": "address"
}
],
"name": "ResultReturnedAddr",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "address[]",
"name": "response",
"type": "address[]"
}
],
"name": "ResultReturnedAddrArr",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "bool",
"name": "response",
"type": "bool"
}
],
"name": "ResultReturnedBool",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "bool[]",
"name": "response",
"type": "bool[]"
}
],
"name": "ResultReturnedBoolArr",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "int16",
"name": "response",
"type": "int16"
}
],
"name": "ResultReturnedI16",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "int16[]",
"name": "response",
"type": "int16[]"
}
],
"name": "ResultReturnedI16Arr",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "int256",
"name": "response",
"type": "int256"
}
],
"name": "ResultReturnedI256",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "int256[]",
"name": "response",
"type": "int256[]"
}
],
"name": "ResultReturnedI256Arr",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "string",
"name": "response",
"type": "string"
}
],
"name": "ResultReturnedStr",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "string[]",
"name": "response",
"type": "string[]"
}
],
"name": "ResultReturnedStrArr",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "string",
"name": "response1",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "response2",
"type": "string"
}
],
"name": "ResultReturnedStrStr",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "string",
"name": "response1",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "response2",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "response3",
"type": "string"
}
],
"name": "ResultReturnedStrStrStr",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "uint16",
"name": "response",
"type": "uint16"
}
],
"name": "ResultReturnedU16",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "uint16[]",
"name": "response",
"type": "uint16[]"
}
],
"name": "ResultReturnedU16Arr",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "uint256",
"name": "response",
"type": "uint256"
}
],
"name": "ResultReturnedU256",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "uint256[]",
"name": "response",
"type": "uint256[]"
}
],
"name": "ResultReturnedU256Arr",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "uint256",
"name": "response1",
"type": "uint256"
},
{
"indexed": false,
"internalType": "string",
"name": "response2",
"type": "string"
}
],
"name": "ResultReturnedU256Str",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "uint256",
"name": "response1",
"type": "uint256"
},
{
"indexed": false,
"internalType": "string",
"name": "response2",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "response3",
"type": "string"
}
],
"name": "ResultReturnedU256StrStr",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "uint256",
"name": "response1",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "response2",
"type": "uint256"
}
],
"name": "ResultReturnedU256U256",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "uint256",
"name": "response1",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "response2",
"type": "uint256"
},
{
"indexed": false,
"internalType": "string",
"name": "response3",
"type": "string"
}
],
"name": "ResultReturnedU256U256Str",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "uint256",
"name": "response1",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "response2",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "response3",
"type": "uint256"
}
],
"name": "ResultReturnedU256U256U256",
"type": "event"
},
{
"inputs": [
{
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"internalType": "string[]",
"name": "response",
"type": "string[]"
}
],
"name": "callback",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"internalType": "uint16",
"name": "response",
"type": "uint16"
}
],
"name": "callback",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint64",
"name": "midpointId",
"type": "uint64"
},
{
"internalType": "bool[]",
"name": "response",
"type": "bool[]"
}
],
"name": "callback",