pragma solidity ^0.4.24;
import "./AM.sol";
/**
* @title payment management contract
* @dev payment management
* @dev contract
*/
contract PAYMENT {
// transaction
struct payment{
uint256 txId;
address fromAddr;
uint64 fromCurrencyId;
uint256 fromAmount;
address toAddr;
uint64 toCurrencyId;
uint256 toAmount;
address delegator;
uint64 ratio;
}
// admin of the contract
address public admin;
// tx id
uint256 public txId = 0;
// account contract address
mapping(address => address) public accountContractOf_;
// store payments
mapping(uint256 => payment) public paymentOf_;
/**
* Constructor function
*
*/
constructor() public {
admin = msg.sender; // set the creator as admin }
/**
* registerContract
* by bank
*
* @param _accountContract The address of the account contract
*/
function registerContract(address _accountContract) public returns (bool success) {
accountContractOf_[msg.sender] = _accountContract;
return true;
}
/**
* transfer
* by bank
*
* @param _from the from address of payment
* @param _fromCurrencyId the from currencency id
* @param _to the to address of payment
* @param _toCurrencyId the to currencency id
* @param _toAmount the amount to send
*/
function transfer(address _from, uint64 _fromCurrencyId, address _to, uint64 _toCurrencyId,
uint256 _toAmount) public returns (bool success) {
if (msg.sender != _from) {
return false;
}
payment storage pay = paymentOf_[txId];
pay.txId = txId;
pay.fromAddr = _from;
pay.fromCurrencyId = _fromCurrencyId;
pay.toAddr = _to;
pay.toCurrencyId = _toCurrencyId;
pay.toAmount = _toAmount;
paymentOf_[txId] = pay;
return true;
}
/**
* delegateTransfer
* by market maker *
* fromAmount = _toAmount/ratio
*
* @param _txId the id of transaction
* @param _ratio the exchange rate
*/
function delegateTransfer(uint256 _txId, uint64 _ratio) public returns (bool success) {
uint256 fromAmount = paymentOf_[_txId].toAmount/_ratio;
paymentOf_[_txId].fromAmount = fromAmount;
paymentOf_[_txId].delegator = msg.sender;
paymentOf_[_txId].ratio = _ratio;
return true;
}
/**
* confirmTransfer
* by bank
*
* @param _txId the id of transaction
*/
function confirmTransfer(uint256 _txId) public returns (bool success) {
if (msg.sender != paymentOf_[_txId].toAddr) {
return false;
}
payment storage pay = paymentOf_[_txId];
address fromAddr;
address toAddr;
address fromContract;
address toContract;
fromAddr = paymentOf_[_txId].fromAddr;
to Addr = paymentOf_[_txId].toAddr;
fromContract = accountContractOf_[fromAddr];
to Contract = accountContractOf_[toAddr];
AM fromAccountManager = AM(fromContract);
AM toAccountManager = AM(toContract);
if (fromAccountManager.getAccount(pay.delegator, pay.fromCurrencyId) < pay.fromAmount) {
return false;
}
if (toAccountManager.getAccount(pay.delegator, pay.toCurrencyId) < pay.toAmount) {
return false;
}
fromAccountManager.increaseAccount(pay.delegator, pay.fromCurrencyId, pay.fromAm
ount);
to AccountManager.decreaseAccount(pay.delegator, pay.toCurrencyId, pay.toAmount);
return true;
}
}
显示如下错误
相似问题