feat: Setup APIs to connect to Ethereum smart contracts #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The API endpoints are as follows. Outstanding actions are the unchecked bulletpoints.
Substrate API endpoints are already included in lib/service/substrateApi
Ethereum API endpoints are included within subdirectories of lib/service/ethereumApi.
The lib/service/ethereumApi/api.dart file is used to connect to the Ethereum network via Infura (to try it out you'll need to setup an Infura account and add your own project id in the .env file).
connectToWeb3EthereumClient
(see comments in the file for details)The lib/service/ethereumApi/apiAccount.dart file is used to fetch a sample Ethereum address' private key from the dotenv file.
getOwnAddress
Since we're only querying the user's Ethereum account information from the Ethereum blockchain, we only need their Ethereum public key address, so we want the user to be able to add their Ethereum public key address in the app's settings, or just scan their address to import it using a QR scanner.
The lib/service/ethereumApi/apiAssetsMXC.dart file is used to query a sample user account's MXC token balance from the Ethereum mainnet.
getAccountBalanceFromMXCContract // Get an account balance of MXC tokens on the Ethereum network
The lib/service/ethereumApi/apiAssetsIOTAPegged.dart file is used to query a sample user account's IOTA Pegged token balance from the IOTA Pegged smart contract (DataHighwayMiningIOTAPeggedContract) that we'll deploy on the Ethereum network. The ABI of that smart contract should be copy/pasted into assets/data/abi_datahighway_iota_pegged_mining_mainnet.json
getAccountBalanceIOTAPeggedFromDataHighwayMiningIOTAPeggedContract
The lib/service/ethereumApi/apiAssetsMiningIOTAPegged.dart file is used to query the DataHighwayMiningIOTAPeggedContract smart contract for the amount of IOTA pegged tokens that have been signalled, and to get the amount that have been signalled whose rewards have either been claimed and pending approval, or approved, or rejected. There are methods in app/lib/page/assets/index.dart that call these API methods and perform calculations before rendering the data in the Mining tab of the UI.
getAccountSignalledIOTAPeggedAmountFromDataHighwayIOTAPeggedMiningContract
getAccountSignalledClaimsPendingOfIOTAPeggedAmountFromDataHighwayIOTAPeggedMiningContract
getAccountSignalledClaimsApprovedOfIOTAPeggedAmountFromDataHighwayIOTAPeggedMiningContract
getAccountSignalledClaimsRejectedOfIOTAPeggedAmountFromDataHighwayIOTAPeggedMiningContract
Refactor methods in UI to use Flutter best practice and make sure it works with mock data. i.e. at the moment I'm passing the functions (i.e.
_fetchMXCBalance
) down so their available to child widgets (i.e.item
) along with the context as follows. This looks wrong, what is a 'Flutter way' to do this properly?The lib/service/ethereumApi/apiAssetsMiningMXC.dart file is used to query the DataHighwayMiningMXCContract for the amount of MXC tokens that have been locked or signalled, and to get the amount that have been locked or signalled whose rewards have either been claimed and pending approval, or approved, or rejected. There are methods in app/lib/page/assets/index.dart that call these API methods and perform calculations before rendering the data in the Mining tab of the UI.
getAccountSignalledMXCAmountFromDataHighwayMXCMiningContract
getAccountSignalledClaimsPendingOfMXCAmountFromDataHighwayMXCMiningContract
getAccountSignalledClaimsApprovedOfMXCAmountFromDataHighwayMXCMiningContract
getAccountSignalledClaimsRejectedOfMXCAmountFromDataHighwayMXCMiningContract
getAccountLockedMXCAmountFromDataHighwayMXCMiningContract
getAccountLockedClaimsPendingOfMXCAmountFromDataHighwayMXCMiningContract
getAccountLockedClaimsApprovedOfMXCAmountFromDataHighwayMXCMiningContract
getAccountLockedClaimsRejectedOfMXCAmountFromDataHighwayMXCMiningContract
Refactor methods in UI to use Flutter best practice and make sure it works with mock data, see previous comment.
Note that two other outstanding issues that are preventing it from compiling include:
MobXCaughtException: NoSuchMethodError: The getter 'isNotEmpty' was called on null. Received: null. Tried calling: isNotEmpty. See also: https://flutter.dev/docs/testing/errors.
UPDATE FIXED IN COMMIT 84e4013