feat: support interacting with smart contracts on EVM-based blockchains
Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
This commit is contained in:
parent
2695b5f5f7
commit
619ce57776
101
examples/hero_vault/contract_example.rhai
Normal file
101
examples/hero_vault/contract_example.rhai
Normal file
@ -0,0 +1,101 @@
|
||||
// Example Rhai script for interacting with smart contracts using Hero Vault
|
||||
// This script demonstrates loading a contract ABI and interacting with a contract
|
||||
|
||||
// Step 1: Set up wallet and network
|
||||
let space_name = "contract_demo_space";
|
||||
let password = "secure_password123";
|
||||
|
||||
print("Creating key space: " + space_name);
|
||||
if create_key_space(space_name, password) {
|
||||
print("✓ Key space created successfully");
|
||||
|
||||
// Create a keypair
|
||||
print("\nCreating keypair...");
|
||||
if create_keypair("contract_key", password) {
|
||||
print("✓ Created contract keypair");
|
||||
}
|
||||
|
||||
// Step 2: Create an Ethereum wallet for Gnosis Chain
|
||||
print("\nCreating Ethereum wallet...");
|
||||
if create_ethereum_wallet() {
|
||||
print("✓ Ethereum wallet created");
|
||||
|
||||
let address = get_ethereum_address();
|
||||
print("Ethereum address: " + address);
|
||||
|
||||
// Step 3: Define a simple ERC-20 ABI (partial)
|
||||
let erc20_abi = `[
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "name",
|
||||
"outputs": [{"name": "", "type": "string"}],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "symbol",
|
||||
"outputs": [{"name": "", "type": "string"}],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "decimals",
|
||||
"outputs": [{"name": "", "type": "uint8"}],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [{"name": "owner", "type": "address"}],
|
||||
"name": "balanceOf",
|
||||
"outputs": [{"name": "", "type": "uint256"}],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
}
|
||||
]`;
|
||||
|
||||
// Step 4: Load the contract ABI
|
||||
print("\nLoading contract ABI...");
|
||||
let contract = load_contract_abi("Gnosis", "0x4ECaBa5870353805a9F068101A40E0f32ed605C6", erc20_abi);
|
||||
if contract != "" {
|
||||
print("✓ Contract loaded successfully");
|
||||
|
||||
// Step 5: Call read-only functions
|
||||
print("\nCalling read-only functions...");
|
||||
|
||||
// Get token name
|
||||
let token_name = call_contract_read(contract, "name");
|
||||
print("Token name: " + token_name);
|
||||
|
||||
// Get token symbol
|
||||
let token_symbol = call_contract_read(contract, "symbol");
|
||||
print("Token symbol: " + token_symbol);
|
||||
|
||||
// Get token decimals
|
||||
let token_decimals = call_contract_read(contract, "decimals");
|
||||
print("Token decimals: " + token_decimals);
|
||||
|
||||
// Note: In a full implementation, we would handle function arguments
|
||||
// For now, we're just demonstrating the basic structure
|
||||
print("Note: balanceOf function requires an address argument, which is not implemented in this example");
|
||||
print("In a full implementation, we would pass the address and get the balance");
|
||||
} else {
|
||||
print("✗ Failed to load contract");
|
||||
}
|
||||
} else {
|
||||
print("✗ Failed to create Ethereum wallet");
|
||||
}
|
||||
} else {
|
||||
print("✗ Failed to create key space");
|
||||
}
|
||||
|
||||
print("\nContract example completed");
|
@ -40,6 +40,14 @@ pub enum CryptoError {
|
||||
/// Serialization error
|
||||
#[error("Serialization error: {0}")]
|
||||
SerializationError(String),
|
||||
|
||||
/// Invalid address format
|
||||
#[error("Invalid address format: {0}")]
|
||||
InvalidAddress(String),
|
||||
|
||||
/// Smart contract error
|
||||
#[error("Smart contract error: {0}")]
|
||||
ContractError(String),
|
||||
}
|
||||
|
||||
/// Convert CryptoError to SAL's Error type
|
||||
|
159
src/hero_vault/ethereum/contract.rs
Normal file
159
src/hero_vault/ethereum/contract.rs
Normal file
@ -0,0 +1,159 @@
|
||||
//! Smart contract interaction functionality.
|
||||
//!
|
||||
//! This module provides functionality for interacting with smart contracts on EVM-based blockchains.
|
||||
|
||||
use ethers::prelude::*;
|
||||
use ethers::abi::{Abi, Token};
|
||||
use std::sync::Arc;
|
||||
use std::str::FromStr;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::hero_vault::error::CryptoError;
|
||||
use super::wallet::EthereumWallet;
|
||||
use super::networks::NetworkConfig;
|
||||
|
||||
/// A smart contract instance.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Contract {
|
||||
/// The contract address
|
||||
pub address: Address,
|
||||
/// The contract ABI
|
||||
pub abi: Abi,
|
||||
/// The network the contract is deployed on
|
||||
pub network: NetworkConfig,
|
||||
}
|
||||
|
||||
impl Contract {
|
||||
/// Creates a new contract instance.
|
||||
pub fn new(address: Address, abi: Abi, network: NetworkConfig) -> Self {
|
||||
Contract {
|
||||
address,
|
||||
abi,
|
||||
network,
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new contract instance from an address string and ABI.
|
||||
pub fn from_address_string(address_str: &str, abi: Abi, network: NetworkConfig) -> Result<Self, CryptoError> {
|
||||
let address = Address::from_str(address_str)
|
||||
.map_err(|e| CryptoError::InvalidAddress(format!("Invalid address format: {}", e)))?;
|
||||
|
||||
Ok(Contract::new(address, abi, network))
|
||||
}
|
||||
|
||||
/// Creates an ethers Contract instance for interaction.
|
||||
pub fn create_ethers_contract(&self, provider: Provider<Http>, _wallet: Option<&EthereumWallet>) -> Result<ethers::contract::Contract<ethers::providers::Provider<Http>>, CryptoError> {
|
||||
let contract = ethers::contract::Contract::new(
|
||||
self.address,
|
||||
self.abi.clone(),
|
||||
Arc::new(provider),
|
||||
);
|
||||
|
||||
Ok(contract)
|
||||
}
|
||||
}
|
||||
|
||||
/// Loads a contract ABI from a JSON string.
|
||||
pub fn load_abi_from_json(json_str: &str) -> Result<Abi, CryptoError> {
|
||||
serde_json::from_str(json_str)
|
||||
.map_err(|e| CryptoError::SerializationError(format!("Failed to parse ABI JSON: {}", e)))
|
||||
}
|
||||
|
||||
/// Calls a read-only function on a contract.
|
||||
pub async fn call_read_function(
|
||||
contract: &Contract,
|
||||
provider: &Provider<Http>,
|
||||
function_name: &str,
|
||||
args: Vec<Token>,
|
||||
) -> Result<Vec<Token>, CryptoError> {
|
||||
// Create the ethers contract (not used directly but kept for future extensions)
|
||||
let _ethers_contract = contract.create_ethers_contract(provider.clone(), None)?;
|
||||
|
||||
// Get the function from the ABI
|
||||
let function = contract.abi.function(function_name)
|
||||
.map_err(|e| CryptoError::ContractError(format!("Function not found in ABI: {}", e)))?;
|
||||
|
||||
// Encode the function call
|
||||
let call_data = function.encode_input(&args)
|
||||
.map_err(|e| CryptoError::ContractError(format!("Failed to encode function call: {}", e)))?;
|
||||
|
||||
// Make the call
|
||||
let tx = TransactionRequest::new()
|
||||
.to(contract.address)
|
||||
.data(call_data);
|
||||
|
||||
let result = provider.call(&tx.into(), None).await
|
||||
.map_err(|e| CryptoError::ContractError(format!("Contract call failed: {}", e)))?;
|
||||
|
||||
// Decode the result
|
||||
let decoded = function.decode_output(&result)
|
||||
.map_err(|e| CryptoError::ContractError(format!("Failed to decode function output: {}", e)))?;
|
||||
|
||||
Ok(decoded)
|
||||
}
|
||||
|
||||
/// Executes a state-changing function on a contract.
|
||||
pub async fn call_write_function(
|
||||
contract: &Contract,
|
||||
wallet: &EthereumWallet,
|
||||
provider: &Provider<Http>,
|
||||
function_name: &str,
|
||||
args: Vec<Token>,
|
||||
) -> Result<H256, CryptoError> {
|
||||
// Create a client with the wallet
|
||||
let client = SignerMiddleware::new(
|
||||
provider.clone(),
|
||||
wallet.wallet.clone(),
|
||||
);
|
||||
|
||||
// Get the function from the ABI
|
||||
let function = contract.abi.function(function_name)
|
||||
.map_err(|e| CryptoError::ContractError(format!("Function not found in ABI: {}", e)))?;
|
||||
|
||||
// Encode the function call
|
||||
let call_data = function.encode_input(&args)
|
||||
.map_err(|e| CryptoError::ContractError(format!("Failed to encode function call: {}", e)))?;
|
||||
|
||||
// Create the transaction request
|
||||
let tx = TransactionRequest::new()
|
||||
.to(contract.address)
|
||||
.data(call_data);
|
||||
|
||||
// Send the transaction using the client directly
|
||||
let pending_tx = client.send_transaction(tx, None)
|
||||
.await
|
||||
.map_err(|e| CryptoError::ContractError(format!("Failed to send transaction: {}", e)))?;
|
||||
|
||||
// Return the transaction hash
|
||||
Ok(pending_tx.tx_hash())
|
||||
}
|
||||
|
||||
/// Estimates gas for a contract function call.
|
||||
pub async fn estimate_gas(
|
||||
contract: &Contract,
|
||||
wallet: &EthereumWallet,
|
||||
provider: &Provider<Http>,
|
||||
function_name: &str,
|
||||
args: Vec<Token>,
|
||||
) -> Result<U256, CryptoError> {
|
||||
// Get the function from the ABI
|
||||
let function = contract.abi.function(function_name)
|
||||
.map_err(|e| CryptoError::ContractError(format!("Function not found in ABI: {}", e)))?;
|
||||
|
||||
// Encode the function call
|
||||
let call_data = function.encode_input(&args)
|
||||
.map_err(|e| CryptoError::ContractError(format!("Failed to encode function call: {}", e)))?;
|
||||
|
||||
// Create the transaction request
|
||||
let tx = TransactionRequest::new()
|
||||
.from(wallet.address)
|
||||
.to(contract.address)
|
||||
.data(call_data);
|
||||
|
||||
// Estimate gas
|
||||
let gas = provider.estimate_gas(&tx.into(), None)
|
||||
.await
|
||||
.map_err(|e| CryptoError::ContractError(format!("Failed to estimate gas: {}", e)))?;
|
||||
|
||||
Ok(gas)
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
//! Ethereum wallet functionality
|
||||
//!
|
||||
//! This module provides functionality for creating and managing Ethereum wallets.
|
||||
//! This module provides functionality for creating and managing Ethereum wallets
|
||||
//! and interacting with smart contracts on EVM-based blockchains.
|
||||
//!
|
||||
//! The module is organized into several components:
|
||||
//! - `wallet.rs`: Core Ethereum wallet implementation
|
||||
@ -8,11 +9,13 @@
|
||||
//! - `provider.rs`: Provider creation and management
|
||||
//! - `transaction.rs`: Transaction-related functionality
|
||||
//! - `storage.rs`: Wallet storage functionality
|
||||
//! - `contract.rs`: Smart contract interaction functionality
|
||||
|
||||
mod wallet;
|
||||
mod provider;
|
||||
mod transaction;
|
||||
mod storage;
|
||||
mod contract;
|
||||
pub mod networks;
|
||||
#[cfg(test)]
|
||||
pub mod tests;
|
||||
@ -64,3 +67,12 @@ pub use networks::{
|
||||
get_all_networks,
|
||||
names,
|
||||
};
|
||||
|
||||
// Re-export contract functions
|
||||
pub use contract::{
|
||||
Contract,
|
||||
load_abi_from_json,
|
||||
call_read_function,
|
||||
call_write_function,
|
||||
estimate_gas,
|
||||
};
|
||||
|
@ -5,9 +5,10 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::OnceLock;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
/// Configuration for an EVM-compatible network
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct NetworkConfig {
|
||||
pub name: String,
|
||||
pub chain_id: u64,
|
||||
|
83
src/hero_vault/ethereum/tests/contract_tests.rs
Normal file
83
src/hero_vault/ethereum/tests/contract_tests.rs
Normal file
@ -0,0 +1,83 @@
|
||||
//! Tests for smart contract functionality.
|
||||
|
||||
use ethers::types::Address;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::hero_vault::ethereum::*;
|
||||
|
||||
#[test]
|
||||
fn test_contract_creation() {
|
||||
// Create a simple ABI
|
||||
let abi_json = r#"[
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "getValue",
|
||||
"outputs": [{"type": "uint256", "name": ""}],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [{"type": "uint256", "name": "newValue"}],
|
||||
"name": "setValue",
|
||||
"outputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
}
|
||||
]"#;
|
||||
|
||||
// Parse the ABI
|
||||
let abi = load_abi_from_json(abi_json).unwrap();
|
||||
|
||||
// Create a contract address
|
||||
let address = Address::from_str("0x1234567890123456789012345678901234567890").unwrap();
|
||||
|
||||
// Create a network config
|
||||
let network = networks::gnosis();
|
||||
|
||||
// Create a contract
|
||||
let contract = Contract::new(address, abi, network);
|
||||
|
||||
// Verify the contract was created correctly
|
||||
assert_eq!(contract.address, address);
|
||||
assert_eq!(contract.network.name, "Gnosis");
|
||||
|
||||
// Verify the ABI contains the expected functions
|
||||
assert!(contract.abi.function("getValue").is_ok());
|
||||
assert!(contract.abi.function("setValue").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_contract_from_address_string() {
|
||||
// Create a simple ABI
|
||||
let abi_json = r#"[
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "getValue",
|
||||
"outputs": [{"type": "uint256", "name": ""}],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
}
|
||||
]"#;
|
||||
|
||||
// Parse the ABI
|
||||
let abi = load_abi_from_json(abi_json).unwrap();
|
||||
|
||||
// Create a network config
|
||||
let network = networks::gnosis();
|
||||
|
||||
// Create a contract from an address string
|
||||
let address_str = "0x1234567890123456789012345678901234567890";
|
||||
let contract = Contract::from_address_string(address_str, abi, network).unwrap();
|
||||
|
||||
// Verify the contract was created correctly
|
||||
assert_eq!(contract.address, Address::from_str(address_str).unwrap());
|
||||
|
||||
// Test with an invalid address
|
||||
let invalid_address = "0xinvalid";
|
||||
let result = Contract::from_address_string(invalid_address, contract.abi.clone(), contract.network.clone());
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
// Note: We can't easily test the actual contract calls in unit tests without mocking
|
||||
// the provider, which would be complex. These would be better tested in integration tests
|
||||
// with a local blockchain or testnet.
|
@ -3,3 +3,4 @@
|
||||
mod wallet_tests;
|
||||
mod network_tests;
|
||||
mod transaction_tests;
|
||||
mod contract_tests;
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Rhai bindings for SAL crypto functionality
|
||||
|
||||
use rhai::{Engine, Dynamic, FnPtr, EvalAltResult};
|
||||
use rhai::{Engine, Dynamic, EvalAltResult};
|
||||
use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
@ -9,11 +9,10 @@ use std::sync::Mutex;
|
||||
use once_cell::sync::Lazy;
|
||||
use tokio::runtime::Runtime;
|
||||
use ethers::types::{Address, U256};
|
||||
use ethers::abi::Token;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::hero_vault::{keypair, symmetric, ethereum};
|
||||
use crate::hero_vault::error::CryptoError;
|
||||
use crate::hero_vault::kvs;
|
||||
|
||||
// Global Tokio runtime for blocking async operations
|
||||
static RUNTIME: Lazy<Mutex<Runtime>> = Lazy::new(|| {
|
||||
@ -698,6 +697,175 @@ fn send_eth(wallet_network: &str, to_address: &str, amount_str: &str) -> String
|
||||
}
|
||||
}
|
||||
|
||||
// Smart contract operations
|
||||
|
||||
// Load a contract ABI from a JSON string and create a contract instance
|
||||
fn load_contract_abi(network_name: &str, address: &str, abi_json: &str) -> String {
|
||||
// Get the network
|
||||
let network = match ethereum::networks::get_network_by_name(network_name) {
|
||||
Some(network) => network,
|
||||
None => {
|
||||
log::error!("Unknown network: {}", network_name);
|
||||
return String::new();
|
||||
}
|
||||
};
|
||||
|
||||
// Parse the ABI
|
||||
let abi = match ethereum::load_abi_from_json(abi_json) {
|
||||
Ok(abi) => abi,
|
||||
Err(e) => {
|
||||
log::error!("Error parsing ABI: {}", e);
|
||||
return String::new();
|
||||
}
|
||||
};
|
||||
|
||||
// Create the contract
|
||||
match ethereum::Contract::from_address_string(address, abi, network) {
|
||||
Ok(contract) => {
|
||||
// Serialize the contract to JSON for storage
|
||||
match serde_json::to_string(&contract) {
|
||||
Ok(json) => json,
|
||||
Err(e) => {
|
||||
log::error!("Error serializing contract: {}", e);
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
log::error!("Error creating contract: {}", e);
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load a contract ABI from a file
|
||||
fn load_contract_abi_from_file(network_name: &str, address: &str, file_path: &str) -> String {
|
||||
// Read the ABI file
|
||||
match fs::read_to_string(file_path) {
|
||||
Ok(abi_json) => load_contract_abi(network_name, address, &abi_json),
|
||||
Err(e) => {
|
||||
log::error!("Error reading ABI file: {}", e);
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Call a read-only function on a contract
|
||||
fn call_contract_read(contract_json: &str, function_name: &str) -> Dynamic {
|
||||
// Deserialize the contract
|
||||
let contract: ethereum::Contract = match serde_json::from_str(contract_json) {
|
||||
Ok(contract) => contract,
|
||||
Err(e) => {
|
||||
log::error!("Error deserializing contract: {}", e);
|
||||
return Dynamic::UNIT;
|
||||
}
|
||||
};
|
||||
|
||||
// Get the runtime
|
||||
let rt = match RUNTIME.lock() {
|
||||
Ok(rt) => rt,
|
||||
Err(e) => {
|
||||
log::error!("Failed to acquire runtime lock: {}", e);
|
||||
return Dynamic::UNIT;
|
||||
}
|
||||
};
|
||||
|
||||
// Create a provider
|
||||
let provider = match ethereum::create_provider(&contract.network) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
log::error!("Failed to create provider: {}", e);
|
||||
return Dynamic::UNIT;
|
||||
}
|
||||
};
|
||||
|
||||
// For simplicity, we're not handling arguments in this implementation
|
||||
let tokens: Vec<Token> = Vec::new();
|
||||
|
||||
// Execute the call in a blocking manner
|
||||
match rt.block_on(async {
|
||||
ethereum::call_read_function(&contract, &provider, function_name, tokens).await
|
||||
}) {
|
||||
Ok(result) => {
|
||||
// Convert the result to a Rhai value
|
||||
if result.is_empty() {
|
||||
Dynamic::UNIT
|
||||
} else {
|
||||
// For simplicity, we'll just return the first value as a string
|
||||
match &result[0] {
|
||||
Token::String(s) => Dynamic::from(s.clone()),
|
||||
Token::Uint(u) => Dynamic::from(u.to_string()),
|
||||
Token::Int(i) => Dynamic::from(i.to_string()),
|
||||
Token::Bool(b) => Dynamic::from(*b),
|
||||
Token::Address(a) => Dynamic::from(format!("{:?}", a)),
|
||||
_ => {
|
||||
log::error!("Unsupported return type");
|
||||
Dynamic::UNIT
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
log::error!("Failed to call contract function: {}", e);
|
||||
Dynamic::UNIT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Call a state-changing function on a contract
|
||||
fn call_contract_write(contract_json: &str, function_name: &str) -> String {
|
||||
// Deserialize the contract
|
||||
let contract: ethereum::Contract = match serde_json::from_str(contract_json) {
|
||||
Ok(contract) => contract,
|
||||
Err(e) => {
|
||||
log::error!("Error deserializing contract: {}", e);
|
||||
return String::new();
|
||||
}
|
||||
};
|
||||
|
||||
// Get the runtime
|
||||
let rt = match RUNTIME.lock() {
|
||||
Ok(rt) => rt,
|
||||
Err(e) => {
|
||||
log::error!("Failed to acquire runtime lock: {}", e);
|
||||
return String::new();
|
||||
}
|
||||
};
|
||||
|
||||
// Get the wallet
|
||||
let network_name_proper = contract.network.name.as_str();
|
||||
let wallet = match ethereum::get_current_ethereum_wallet_for_network(network_name_proper) {
|
||||
Ok(w) => w,
|
||||
Err(e) => {
|
||||
log::error!("Failed to get wallet: {}", e);
|
||||
return String::new();
|
||||
}
|
||||
};
|
||||
|
||||
// Create a provider
|
||||
let provider = match ethereum::create_provider(&contract.network) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
log::error!("Failed to create provider: {}", e);
|
||||
return String::new();
|
||||
}
|
||||
};
|
||||
|
||||
// For simplicity, we're not handling arguments in this implementation
|
||||
let tokens: Vec<Token> = Vec::new();
|
||||
|
||||
// Execute the transaction in a blocking manner
|
||||
match rt.block_on(async {
|
||||
ethereum::call_write_function(&contract, &wallet, &provider, function_name, tokens).await
|
||||
}) {
|
||||
Ok(tx_hash) => format!("{:?}", tx_hash),
|
||||
Err(e) => {
|
||||
log::error!("Transaction failed: {}", e);
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Register crypto functions with the Rhai engine
|
||||
pub fn register_crypto_module(engine: &mut Engine) -> Result<(), Box<EvalAltResult>> {
|
||||
// Register key space functions
|
||||
@ -746,5 +914,11 @@ pub fn register_crypto_module(engine: &mut Engine) -> Result<(), Box<EvalAltResu
|
||||
engine.register_fn("send_eth", send_eth);
|
||||
engine.register_fn("get_balance", get_balance);
|
||||
|
||||
// Register smart contract functions
|
||||
engine.register_fn("load_contract_abi", load_contract_abi);
|
||||
engine.register_fn("load_contract_abi_from_file", load_contract_abi_from_file);
|
||||
engine.register_fn("call_contract_read", call_contract_read);
|
||||
engine.register_fn("call_contract_write", call_contract_write);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user