Hi, Can someone help me out? The transfer part of my code works fine, but ‘getTransaction’ which should log the transaction to the government contract does not work. Everything is compiled right but I get error message…call to Financial.getTransaction errored: VM error: invalid opcode.
‘invalid opcode
call to financial.getTransaction errored
Debug the transaction to get more information’
pragma solidity 0.7.5;
import “./Ownable.sol”;
//External contract wants to pull transaction data form this(bankOwnable) contract//
interface FinancialInterface {
function addTransaction (address _from, address _to, uint _amount) external;
}
contract bank is Ownable {
FinancialInterface FinancialInstance = FinancialInterface(0xf8e81D47203A594245E36C48e151709F0C19fBe8);
mapping (address => uint) balance;
event depositDone(uint amount, address indexed depositedTo);
function deposit() public payable returns (uint) {
balance[msg.sender] += msg.value;
emit depositDone (msg.value, msg.sender);
return balance[msg.sender];
}
function withdraw(uint amount) public onlyOwner returns (uint) {
require(balance[msg.sender]>= amount);
balance[msg.sender] -= amount;
msg.sender.transfer(amount);
return balance[msg.sender];
}
function getBalance()public view returns(uint){
return balance[msg.sender];
}
function transfer(address recipient, uint amount) public {
require(balance[msg.sender] >= amount, "Insufficient balance");
require(msg.sender != recipient, "Can not send funds to yourself");
uint previousSenderBalance = balance[msg.sender];
_transfer(msg.sender, recipient, amount);
FinancialInstance.addTransaction(msg.sender, recipient, amount);
assert(balance[msg.sender] == previousSenderBalance - amount);
}
function _transfer(address from, address to, uint amount) private {
balance[from] -= amount;
balance[to] += amount;
}
}
pragma solidity 0.7.5;
contract Financial {
struct Transaction {
address from;
address to;
uint amount;
uint txId;
}
Transaction[] transactionLog;
function addTransaction (address _from, address _to, uint _amount)external {
transactionLog.push( Transaction(_from, _to, _amount, transactionLog.length));
}
function getTransaction(uint _index)public view returns(address, address, uint) {
return (transactionLog[_index].from, transactionLog[_index].to, transactionLog[_index].amount);
}
}
Thanks