Remove actual ethereum contracts and use interfaces instead
This commit is contained in:
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
76
contracts/IAdapter.json
Normal 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": {}
|
||||
}
|
341
contracts/IERC721Metadata.json
Normal file
341
contracts/IERC721Metadata.json
Normal 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
|
@ -1,8 +1,8 @@
|
|||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
pub const COLLECTIBLE: &str = "Collectible";
|
||||
pub const MANAGER: &str = "Manager";
|
||||
pub const ADAPTER: &str = "IAdapter";
|
||||
pub const ERC721: &str = "IERC721Metadata";
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum ArtifactError {
|
||||
|
@ -22,7 +22,8 @@ pub fn load_abi(
|
|||
) -> Result<Vec<u8>, ArtifactError> {
|
||||
let contract_artifact_path = contract_dir.join(format!("{}.json", contract_name));
|
||||
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")
|
||||
.ok_or(ArtifactError::KeyError)?
|
||||
.to_string().as_bytes().to_vec();
|
||||
|
|
|
@ -2,7 +2,7 @@ use web3::contract::{Contract, Options};
|
|||
|
||||
use crate::config::BlockchainConfig;
|
||||
use super::api::connect;
|
||||
use super::contracts::{MANAGER, load_abi};
|
||||
use super::contracts::{ADAPTER, load_abi};
|
||||
use super::errors::EthereumError;
|
||||
use super::utils::parse_address;
|
||||
|
||||
|
@ -11,15 +11,15 @@ pub async fn is_allowed_user(
|
|||
user_address: &str,
|
||||
) -> Result<bool, EthereumError> {
|
||||
let web3 = connect(&config.api_url)?;
|
||||
let manager_abi = load_abi(&config.contract_dir, MANAGER)?;
|
||||
let manager_address = parse_address(&config.contract_address)?;
|
||||
let manager = Contract::from_json(
|
||||
let adapter_abi = load_abi(&config.contract_dir, ADAPTER)?;
|
||||
let adapter_address = parse_address(&config.contract_address)?;
|
||||
let adapter = Contract::from_json(
|
||||
web3.eth(),
|
||||
manager_address,
|
||||
&manager_abi,
|
||||
adapter_address,
|
||||
&adapter_abi,
|
||||
)?;
|
||||
let user_address = parse_address(user_address)?;
|
||||
let result: bool = manager.query(
|
||||
let result: bool = adapter.query(
|
||||
"isAllowedUser", (user_address,),
|
||||
None, Options::default(), None,
|
||||
).await?;
|
||||
|
|
|
@ -21,7 +21,7 @@ use crate::models::posts::queries::{
|
|||
get_token_waitlist,
|
||||
};
|
||||
use super::api::connect;
|
||||
use super::contracts::{MANAGER, COLLECTIBLE, load_abi};
|
||||
use super::contracts::{ADAPTER, ERC721, load_abi};
|
||||
use super::errors::EthereumError;
|
||||
use super::signatures::{sign_contract_call, CallArgs, SignatureData};
|
||||
use super::utils::parse_address;
|
||||
|
@ -32,19 +32,19 @@ pub async fn get_nft_contract(
|
|||
config: &BlockchainConfig,
|
||||
) -> Result<(Web3<Http>, Contract<Http>), EthereumError> {
|
||||
let web3 = connect(&config.api_url)?;
|
||||
let manager_abi = load_abi(&config.contract_dir, MANAGER)?;
|
||||
let manager_address = parse_address(&config.contract_address)?;
|
||||
let manager = Contract::from_json(
|
||||
let adapter_abi = load_abi(&config.contract_dir, ADAPTER)?;
|
||||
let adapter_address = parse_address(&config.contract_address)?;
|
||||
let adapter = Contract::from_json(
|
||||
web3.eth(),
|
||||
manager_address,
|
||||
&manager_abi,
|
||||
adapter_address,
|
||||
&adapter_abi,
|
||||
)?;
|
||||
|
||||
let token_address = manager.query(
|
||||
let token_address = adapter.query(
|
||||
"collectible",
|
||||
(), None, Options::default(), None,
|
||||
).await?;
|
||||
let token_abi = load_abi(&config.contract_dir, COLLECTIBLE)?;
|
||||
let token_abi = load_abi(&config.contract_dir, ERC721)?;
|
||||
let token = Contract::from_json(
|
||||
web3.eth(),
|
||||
token_address,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::ethereum::contracts::MANAGER;
|
||||
use crate::ethereum::contracts::ADAPTER;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct InstanceInfo {
|
||||
|
@ -32,7 +32,7 @@ impl From<&Config> for InstanceInfo {
|
|||
blockchain_explorer_url: config.blockchain.as_ref()
|
||||
.and_then(|val| val.explorer_url.clone()),
|
||||
blockchain_contract_name: config.blockchain.as_ref()
|
||||
.and(Some(MANAGER.into())),
|
||||
.and(Some(ADAPTER.into())),
|
||||
blockchain_contract_address: config.blockchain.as_ref()
|
||||
.map(|val| val.contract_address.clone()),
|
||||
ipfs_gateway_url: config.ipfs_gateway_url.clone(),
|
||||
|
|
Loading…
Reference in a new issue