Remove actual ethereum contracts and use interfaces instead

This commit is contained in:
silverpill 2022-01-26 16:59:27 +00:00
parent 237185bb14
commit a3f20149cf
9 changed files with 438 additions and 1063 deletions

File diff suppressed because one or more lines are too long

76
contracts/IAdapter.json Normal file
View file

@ -0,0 +1,76 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "IAdapter",
"sourceName": "contracts/IAdapter.sol",
"abi": [
{
"inputs": [],
"name": "collectible",
"outputs": [
{
"internalType": "contract IERC721Metadata",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "user",
"type": "address"
}
],
"name": "isAllowedUser",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "user",
"type": "address"
},
{
"internalType": "string",
"name": "tokenURI",
"type": "string"
},
{
"internalType": "uint8",
"name": "v",
"type": "uint8"
},
{
"internalType": "bytes32",
"name": "r",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "s",
"type": "bytes32"
}
],
"name": "mint",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x",
"deployedBytecode": "0x",
"linkReferences": {},
"deployedLinkReferences": {}
}

View file

@ -0,0 +1,341 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "IERC721Metadata",
"sourceName": "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "approved",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"indexed": false,
"internalType": "bool",
"name": "approved",
"type": "bool"
}
],
"name": "ApprovalForAll",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "approve",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "balance",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "getApproved",
"outputs": [
{
"internalType": "address",
"name": "operator",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "operator",
"type": "address"
}
],
"name": "isApprovedForAll",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "ownerOf",
"outputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "safeTransferFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "safeTransferFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"internalType": "bool",
"name": "_approved",
"type": "bool"
}
],
"name": "setApprovalForAll",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes4",
"name": "interfaceId",
"type": "bytes4"
}
],
"name": "supportsInterface",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "tokenURI",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x",
"deployedBytecode": "0x",
"linkReferences": {},
"deployedLinkReferences": {}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,8 +1,8 @@
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
pub const COLLECTIBLE: &str = "Collectible"; pub const ADAPTER: &str = "IAdapter";
pub const MANAGER: &str = "Manager"; pub const ERC721: &str = "IERC721Metadata";
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub enum ArtifactError { pub enum ArtifactError {
@ -22,7 +22,8 @@ pub fn load_abi(
) -> Result<Vec<u8>, ArtifactError> { ) -> Result<Vec<u8>, ArtifactError> {
let contract_artifact_path = contract_dir.join(format!("{}.json", contract_name)); let contract_artifact_path = contract_dir.join(format!("{}.json", contract_name));
let contract_artifact = fs::read_to_string(contract_artifact_path)?; let contract_artifact = fs::read_to_string(contract_artifact_path)?;
let contract_artifact_value: serde_json::Value = serde_json::from_str(&contract_artifact)?; let contract_artifact_value: serde_json::Value =
serde_json::from_str(&contract_artifact)?;
let contract_abi = contract_artifact_value.get("abi") let contract_abi = contract_artifact_value.get("abi")
.ok_or(ArtifactError::KeyError)? .ok_or(ArtifactError::KeyError)?
.to_string().as_bytes().to_vec(); .to_string().as_bytes().to_vec();

View file

@ -2,7 +2,7 @@ use web3::contract::{Contract, Options};
use crate::config::BlockchainConfig; use crate::config::BlockchainConfig;
use super::api::connect; use super::api::connect;
use super::contracts::{MANAGER, load_abi}; use super::contracts::{ADAPTER, load_abi};
use super::errors::EthereumError; use super::errors::EthereumError;
use super::utils::parse_address; use super::utils::parse_address;
@ -11,15 +11,15 @@ pub async fn is_allowed_user(
user_address: &str, user_address: &str,
) -> Result<bool, EthereumError> { ) -> Result<bool, EthereumError> {
let web3 = connect(&config.api_url)?; let web3 = connect(&config.api_url)?;
let manager_abi = load_abi(&config.contract_dir, MANAGER)?; let adapter_abi = load_abi(&config.contract_dir, ADAPTER)?;
let manager_address = parse_address(&config.contract_address)?; let adapter_address = parse_address(&config.contract_address)?;
let manager = Contract::from_json( let adapter = Contract::from_json(
web3.eth(), web3.eth(),
manager_address, adapter_address,
&manager_abi, &adapter_abi,
)?; )?;
let user_address = parse_address(user_address)?; let user_address = parse_address(user_address)?;
let result: bool = manager.query( let result: bool = adapter.query(
"isAllowedUser", (user_address,), "isAllowedUser", (user_address,),
None, Options::default(), None, None, Options::default(), None,
).await?; ).await?;

View file

@ -21,7 +21,7 @@ use crate::models::posts::queries::{
get_token_waitlist, get_token_waitlist,
}; };
use super::api::connect; use super::api::connect;
use super::contracts::{MANAGER, COLLECTIBLE, load_abi}; use super::contracts::{ADAPTER, ERC721, load_abi};
use super::errors::EthereumError; use super::errors::EthereumError;
use super::signatures::{sign_contract_call, CallArgs, SignatureData}; use super::signatures::{sign_contract_call, CallArgs, SignatureData};
use super::utils::parse_address; use super::utils::parse_address;
@ -32,19 +32,19 @@ pub async fn get_nft_contract(
config: &BlockchainConfig, config: &BlockchainConfig,
) -> Result<(Web3<Http>, Contract<Http>), EthereumError> { ) -> Result<(Web3<Http>, Contract<Http>), EthereumError> {
let web3 = connect(&config.api_url)?; let web3 = connect(&config.api_url)?;
let manager_abi = load_abi(&config.contract_dir, MANAGER)?; let adapter_abi = load_abi(&config.contract_dir, ADAPTER)?;
let manager_address = parse_address(&config.contract_address)?; let adapter_address = parse_address(&config.contract_address)?;
let manager = Contract::from_json( let adapter = Contract::from_json(
web3.eth(), web3.eth(),
manager_address, adapter_address,
&manager_abi, &adapter_abi,
)?; )?;
let token_address = manager.query( let token_address = adapter.query(
"collectible", "collectible",
(), None, Options::default(), None, (), None, Options::default(), None,
).await?; ).await?;
let token_abi = load_abi(&config.contract_dir, COLLECTIBLE)?; let token_abi = load_abi(&config.contract_dir, ERC721)?;
let token = Contract::from_json( let token = Contract::from_json(
web3.eth(), web3.eth(),
token_address, token_address,

View file

@ -1,7 +1,7 @@
use serde::Serialize; use serde::Serialize;
use crate::config::Config; use crate::config::Config;
use crate::ethereum::contracts::MANAGER; use crate::ethereum::contracts::ADAPTER;
#[derive(Serialize)] #[derive(Serialize)]
pub struct InstanceInfo { pub struct InstanceInfo {
@ -32,7 +32,7 @@ impl From<&Config> for InstanceInfo {
blockchain_explorer_url: config.blockchain.as_ref() blockchain_explorer_url: config.blockchain.as_ref()
.and_then(|val| val.explorer_url.clone()), .and_then(|val| val.explorer_url.clone()),
blockchain_contract_name: config.blockchain.as_ref() blockchain_contract_name: config.blockchain.as_ref()
.and(Some(MANAGER.into())), .and(Some(ADAPTER.into())),
blockchain_contract_address: config.blockchain.as_ref() blockchain_contract_address: config.blockchain.as_ref()
.map(|val| val.contract_address.clone()), .map(|val| val.contract_address.clone()),
ipfs_gateway_url: config.ipfs_gateway_url.clone(), ipfs_gateway_url: config.ipfs_gateway_url.clone(),