Add mapping with additional blockchain info to instance API response

This commit is contained in:
silverpill 2022-06-22 21:37:59 +00:00
parent 6172d309bc
commit 6b06d6d18e
5 changed files with 15 additions and 0 deletions

View file

@ -13,6 +13,7 @@ registrations_open: true
blockchain: blockchain:
# Parameters for hardhat local node # Parameters for hardhat local node
chain_id: eip155:31337 chain_id: eip155:31337
chain_info: null
contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9' contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
contract_dir: contracts contract_dir: contracts
api_url: 'http://127.0.0.1:8546' api_url: 'http://127.0.0.1:8546'

View file

@ -27,8 +27,10 @@ registrations_open: false
#blocked_instances: [] #blocked_instances: []
# Blockchain integration # Blockchain integration
# Signing key for ethereum integration can be generated with `mitractl generate-ethereum-address`
#blockchain: #blockchain:
# chain_id: eip155:31337 # chain_id: eip155:31337
# chain_info: null
# contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9' # contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
# contract_dir: /usr/share/mitra/contracts # contract_dir: /usr/share/mitra/contracts
# api_url: 'http://127.0.0.1:8545' # api_url: 'http://127.0.0.1:8545'

View file

@ -775,6 +775,10 @@ components:
description: Blockchain contract address. description: Blockchain contract address.
type: string type: string
nullable: true nullable: true
blockchain_info:
description: Additional information about blockchain
type: object
nullable: true
ipfs_gateway_url: ipfs_gateway_url:
description: IPFS gateway URL. description: IPFS gateway URL.
type: string type: string

View file

@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::str::FromStr; use std::str::FromStr;
@ -82,6 +83,8 @@ fn default_post_character_limit() -> usize { 2000 }
pub struct BlockchainConfig { pub struct BlockchainConfig {
// CAIP-2 chain ID (https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md) // CAIP-2 chain ID (https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md)
pub chain_id: String, pub chain_id: String,
// Additional information for clients
pub chain_info: Option<HashMap<String, String>>,
pub contract_address: String, pub contract_address: String,
pub contract_dir: PathBuf, pub contract_dir: PathBuf,
pub api_url: String, pub api_url: String,

View file

@ -1,3 +1,5 @@
use std::collections::HashMap;
use serde::Serialize; use serde::Serialize;
use crate::config::Config; use crate::config::Config;
@ -17,6 +19,7 @@ pub struct InstanceInfo {
blockchain_id: Option<String>, blockchain_id: Option<String>,
blockchain_explorer_url: Option<String>, blockchain_explorer_url: Option<String>,
blockchain_contract_address: Option<String>, blockchain_contract_address: Option<String>,
blockchain_info: Option<HashMap<String, String>>,
ipfs_gateway_url: Option<String>, ipfs_gateway_url: Option<String>,
} }
@ -45,6 +48,8 @@ impl From<&Config> for InstanceInfo {
.and_then(|val| val.explorer_url.clone()), .and_then(|val| val.explorer_url.clone()),
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()),
blockchain_info: config.blockchain.as_ref()
.and_then(|val| val.chain_info.clone()),
ipfs_gateway_url: config.ipfs_gateway_url.clone(), ipfs_gateway_url: config.ipfs_gateway_url.clone(),
} }
} }