Smart contract interface

Balance contract

    event GenesisBalance(address indexed user, bytes32 indexed tokenId, uint balance);
    event BalanceChange(address indexed user, bytes32 indexed tokenId, uint balance);
    event Transfer(address indexed fromAddr, address indexed toAddr, bytes32 indexed tokenId, uint amount);
    event CancelTransfer(address indexed fromAddr, address indexed toAddr, bytes32 indexed tokenId, uint balance);
    event Deposit(address peggingContract, bytes32 tokenId, address toAddr, uint amount);
    event Withdraw(address peggingContract, bytes32 tokenId, address user, address extraUser, bytes destination, uint amount, bytes comment, uint withdrawId, uint feeAmount);
    event GiveBack(address peggingContract, bytes32 tokenId, address user, address extraUser, uint amount, uint feeAmount, uint networkFee, uint backAmount);

    mapping (bytes32 => address) public peggingContracts;
    mapping (bytes32 => bytes32) public tokenIdToSummary;
    mapping (bytes32 => uint) public decimals;
    mapping (bytes32 => bool) public isValidToken;
    mapping (bytes32 => mapping (address => uint)) public balanceOf;
    mapping (address => bool) public isValidPeggingContract;
    mapping (bytes32 => bool) public isUsedTransfer;
    mapping (bytes32 => bool) public isUsedWithdraw;
    mapping (address => bool) public userTransferable;
    mapping (bytes32 => uint) public withdrawFee;

    bool public defaultTransferable;
    uint public withdrawCount = 0;
    address public feeGovernance;
    
    function deposit(bytes32 tokenSummary, address toAddr, uint amount) public
    function deposit(bytes32 tokenSummary, address toAddr, uint amount, address extraToAddr) public
    function giveBack(bytes32 tokenSummary, address toAddr, uint amount, uint networkFee) public
    function giveBack(bytes32 tokenSummary, address toAddr, uint amount, uint networkFee, address extraToAddr) public
    function withdraw(bytes32 tokenId, bytes memory destination, uint amount, bytes memory comment) public
    function withdraw(bytes32 tokenId, address extraUser, bytes memory destination, uint amount, bytes memory comment) public
    function withdrawBySignature(bytes32[] memory bytes32s, uint[] memory uints, address fromAddr, bytes memory destination, bytes memory comment, uint8 v) public
    function cancelWithdrawSignature(address fromAddr, bytes32 tokenId, bytes memory destination, uint amount, bytes memory comment, uint expireTime, bytes32 wNonce, uint8 v, bytes32 r, bytes32 s) public
    function transfer(bytes32 tokenId, address toAddr, uint amount, bool needLog) public
    function transfer(bytes32 tokenId, address toAddr, uint amount, bool needLog, address extraToAddr) public
    function transferBySignature(bytes32[] memory bytesArr, address[] memory addrs, uint amount, uint8 v, bool onlyToSpender, bool needLog) public
    function transferBySignatureWithExtra(bytes32[] memory bytesArr, address[] memory addrs, uint amount, uint8 v, bool onlyToSpender, bool needLog) public
    function cancelTransferSignature(bytes32[] memory bytesArr, address[] memory addrs, uint amount, uint8 v, bool onlyToSpender) public
    function cancelTransferSignatureWithExtra(bytes32[] memory bytesArr, address[] memory addrs, uint amount, uint8 v, bool onlyToSpender) public
    
    function getBalance(bytes32 tokenId, address addr) public view returns(uint)
    function logBalance(bytes32 tokenId, address addr) public

EthPeggingContract

    event AddToken(address tokenAddr, bytes32 tokenSummary, bytes32 tokenId);
    event RemoveToken(address tokenAddr, bytes32 tokenSummary, bytes32 tokenId);

    event DepositRelay(address mainAddr, address tokenAddr, address addr, address toAddr, uint amount, uint depositId, address extraToAddr);
    event DepositValidated(address mainAddr, address tokenAddr, address addr, address toAddr, uint amount, uint depositId, address extraToAddr);
    
    event WithdrawRelay(uint withdrawId, address balanceContractAddr, bytes32 tokenSummary, address addr, bytes destination, uint amount, bytes comment);
    event WithdrawValidated(uint withdrawId, address balanceContractAddr, bytes32 tokenSummary, address addr, bytes destination, uint amount, bytes comment);

    mapping (bytes32=>bool) public deposits;
    mapping (bytes32=>address) public tokenAddr;
    mapping (address=>bytes32) public tokenSummaries;
    mapping (bytes32=>bool) public isListing;
    
    struct Withdrawal{
        address user;
        bytes32 tokenSummary;
        bytes destination;
        uint amount;
        bytes comment;
    }
    
    mapping (uint=>Withdrawal) public withdrawals;
    
    function relayDepositToken(address mainAddr, address fromAddr, address toAddr, address token, uint amount, uint depositId, address extraToAddr) public
    function validateDepositToken(address mainAddr, address fromAddr, address toAddr, address token, uint amount, uint depositId, address extraToAddr, address validator, uint8 v, bytes32 r, bytes32 s) public
    function checkValidateDepositToken(address mainAddr, address fromAddr,address toAddr, address token, uint amount, uint depositId, address extraToAddr) public
    function withdraw(uint withdrawId, address user, bytes32 tokenSummary, bytes memory destination, uint amount, bytes memory comment) public
    function withdraw(uint withdrawId, address user, address extraUser, bytes32 tokenSummary, bytes memory destination, uint amount, bytes memory comment) public
    function relayWithdraw(uint withdrawId) public
    function validateWithdraw(uint withdrawId, address validator, uint8 v, bytes32 r, bytes32 s) public
    function checkValidateWithdraw(uint withdrawId) public
    

BtcPeggingContract

    struct DepositItem {
        bytes32 txid;
        uint vout;
        uint amount;
        bytes scriptPubKey;
        address toAddr;
        address extraToAddr;
        bool deposited;
        bytes32 depositPubKeyX;
        bytes32 depositPubKeyY;
    }

    struct WithdrawItem {
        uint wtype; // 0: default, 1: send to cold
        uint withdrawId;
        bytes destination;
        uint amount;
    }

    struct Utxo {
        bytes32 txid;
        uint vout;
        uint amount;
        bytes scriptPubKey;
        bool used;
    }

    struct WithdrawTx {
        bytes32 suggestHash;
        bytes32[] keyHashs;
        bytes32[] inputHashs;
        uint outputStart;
        uint outputSize;
        uint fee;
        uint change;
    }
    
    struct Destination {
        address toAddr;
        address extraToAddr;
    }

    mapping(bytes32 => DepositItem) public deposits;
    mapping(uint => WithdrawItem) public withdrawals;
    mapping(bytes32 => Utxo) public utxos;
    mapping(uint => WithdrawTx) public suggestions;
    mapping(uint => WithdrawTx) public selections;
    mapping(uint => bytes32) public utxoKeys;
    mapping(bytes32 => mapping(bytes32 => Destination)) public depositDestinations;
    mapping(bytes32 => bool) public isUsedMappingHash;

    bool public isActivated = true;
    uint public utxoCount = 0;
    uint public validUtxoCount = 0;
    uint public withdrawalCount = 0;
    uint public withdrewCount = 0;
    uint public suggestCount = 0;
    uint public selectionCount = 0;
    uint public btcBalance = 0;
    uint public holdingLimit = 0;

    address tokenAddr = 0x0000000000000000000000000000000000000001;
    bytes coldAddr;
    bytes public redeemScript;
    
    event DepositDestinationsMapping(bytes32 btcPubKeyX, bytes32 btcPubKeyY, address toAddr, address extraToAddr);
    event DepositRelay(bytes32 txid, uint vout, uint amount, bytes scriptPubKey, bytes32 depositPubKeyX, bytes32 depositPubKeyY);
    event DepositValidated(bytes32 txid, uint vout, uint amount, bytes scriptPubKey, address toAddr, address extraToAddr, bytes32 depositPubKeyX, bytes32 depositPubKeyY);
    event WithdrawAdded(address balanceAddr, uint wtype, uint withdrawId, address user, uint withdrawIndex, bytes32 tokenSummary, bytes destination, uint amount);
    event TxSuggestAdded(bytes32 suggestHash, uint suggestIndex, bytes32[] keyHashs, bytes32[] inputHashs, uint outputStart, uint outputSize, uint fee, uint change);
    event TxSuggestRelay(bytes32 suggestHash, uint suggestIndex, bytes32[] keyHashs, bytes32[] inputHashs, uint outputStart, uint outputSize, uint fee, uint change);
    event TxSelected(uint selectionIndex, bytes32[] keyHashs, bytes32[] inputHashs, uint outputStart, uint outputSize, uint fee, uint change);
    event TxSelectedRelay(uint selectionIndex, bytes32[] keyHashs, bytes32[] inputHashs, uint outputStart, uint outputSize, uint fee, uint change);
    event WithdrawValidated(uint selectionIndex, bytes32[] keyHashs, bytes32[] inputHashs, uint outputStart, uint outputSize, uint fee);
    event UsableUtxoRelay(bytes32 txid, uint vout, uint amount, bytes scriptPubKey);
    event UtxoAdded(uint utxoIndex, bytes32 txid, uint vout, uint amount, bytes scriptPubKey, bytes32 keyHash);
    
    function getSuggestKeyHashs(uint suggestIndex) public view returns(bytes32[] memory)
    function getSuggestInputHashs(uint suggestIndex) public view returns(bytes32[] memory)
    function getSelectionKeyHashs(uint selectionIndex) public view returns(bytes32[] memory)
    function getSelectionInputHashs(uint selectionIndex) public view returns(bytes32[] memory)
    function bytes32ToAddress(bytes32 data) public pure returns (address)
    
    function setDepositDestinations(bytes32[] memory btcPubKeyX, bytes32[] memory btcPubKeyY, address[] memory toAddrs, address[] memory extraToAddrs, bytes32[] memory nonces, uint8[] memory v, bytes32[] memory r, bytes32[] memory s) public
    function relayDepositUtxo(bytes32 txid, uint vout, uint amount, bytes memory scriptPubKey, bytes32 depositPubKeyX, bytes32 depositPubKeyY) public onlyActivated
    function relayUsableUtxo(bytes32 txid, uint vout, uint amount, bytes memory scriptPubKey) public
    function validateDepositUtxo(bytes32 depositKeyHash, address validator, uint8 v, bytes32 r, bytes32 s) public onlyActivated
    function validateUsableUtxo(bytes32 txid, uint vout, uint amount, bytes memory scriptPubKey, address validator, uint8 v, bytes32 r, bytes32 s) public
    function withdraw(uint withdrawId, address user, bytes32 tokenSummary, bytes memory destination, uint amount, bytes memory comment) public onlyActivated
    function withdraw(uint withdrawId, address user, address extraUser, bytes32 tokenSummary, bytes memory destination, uint amount, bytes memory comment) public onlyActivated
    function withdrawColdScript() public onlyActivated
    function suggestWithdrawTx(bytes32[] memory keyHashs, bytes32[] memory inputHashs, uint outputSize, uint fee, uint change) public
    function relayTxSuggest(uint suggestIndex) public
    function validateSuggest(bytes32 suggestHash, uint suggestIndex, address validator, uint8 v, bytes32 r, bytes32 s) public
    function relayTxSelected(uint selectionIndex) public
    function validateWithdraw(uint selectionIndex, address validator, uint8[] memory v, bytes32[] memory r, bytes32[] memory s) public
    

XrpPeggingContract

    struct Withdrawal {
        uint wtype; // 0: default, 1: send to cold
        address user;
        address extraUser;
        bytes from;
        bytes dest;
        bytes tag;
        uint amount;
        bool validated;
        bool isCanceled;
        uint fee;
        uint seq;
        mapping(address => bytes32) signatureHashs;
    }

    struct Suggestion {
        address[] validators;
        bytes32[] signatureHashs;
        uint fee;
        uint seq;
    }

    mapping(bytes32 => bool) public isDeposited;
    mapping(uint => Withdrawal) public withdrawals;
    mapping(uint => mapping(uint => Suggestion)) public suggestions;

    bool public isActivated = true;
    uint public withdrawalCount;
    uint public suggestCount;
    uint public lastWithdrew;
    uint public lastSelected;
    uint public lastSequence;
    uint public xrpBalance;
    uint public holdingLimit;
    bytes public xrpWallet;

    bytes coldAddr;
    bytes32 public tSummary = sha256(abi.encodePacked('XRP', address(1)));
    
    event XrpDepositRelay(bytes32 txid, bytes xrpWallet, address toAddr, uint amount, address extraToAddr);
    event XrpDepositValidated(bytes32 txid, bytes xrpWallet, address toAddr, uint amount, address extraToAddr);
    event XrpDepositColdRelay(bytes32 txid, bytes xrpWallet, uint amount);
    event XrpDepositColdValidated(bytes32 txid, bytes xrpWallet, uint amount);
    event XrpWithdrawAdded(uint withdrawId, address balanceAddr, uint withdrawIndex, bytes xrpWallet, uint wtype, address user, address extraUser, bytes dest, bytes tag, uint amount);
    event XrpWithdrawSuggested(uint suggestIndex, uint withdrawIndex, address[] validators, bytes32[] sigHashs, uint fee, uint seq);
    event XrpSuggestionValidated(uint suggestIndex, uint withdrawIndex, uint fee, uint seq);
    event XrpWithdrawValidated(uint withdrawIndex);
    event XrpTransactionFailed(uint withdrawIndex);
    event XrpWithdrawCanceled(uint withdrawIndex);

    function relayDeposit(bytes32 txid, address toAddr, uint amount, address extraToAddr) public onlyActivated
    function relayDepositCold(bytes32 txid, uint amount) public onlyActivated
    function validateDeposit(bytes32 txid, address toAddr, uint amount, address extraToAddr, address validator, uint8 vSig, bytes32 rSig, bytes32 sSig) public
    function validateDepositCold(bytes32 txid, uint amount, address validator, uint8 vSig, bytes32 rSig, bytes32 sSig) public
    function withdraw(uint withdrawId, address user, bytes32 tokenSummary, bytes memory destination, uint amount, bytes memory comment) public onlyActivated
    function withdraw(uint withdrawId, address user, address extraUser, bytes32 tokenSummary, bytes memory destination, uint amount, bytes memory comment) public onlyActivated
    function transferToCold() public
    function suggestWithdraw(uint withdrawIndex, address[] memory validators, bytes32[] memory sigHashs, uint fee, uint seq) public
    function relaySuggestion(uint withdrawIndex, uint suggestIndex) public
    function validateSuggestion(uint withdrawIndex, uint suggestIndex, address validator, uint8 vSig, bytes32 rSig, bytes32 sSig) public
    function relayWithdraw(uint suggestIndex, uint withdrawIndex) public
    function validateWithdraw(uint withdrawIndex, address validator, uint8[] memory vSigs, bytes32[] memory rSigs, bytes32[] memory sSigs) public
    function relayTransactionFailed(uint withdrawIndex) public
    function cancelWithdraw(uint withdrawIndex, address validator, uint8 vSig, bytes32 rSig, bytes32 sSig) public
    
    function withdrawIndexToSuggest() public view returns(uint)
    function withdrawIndexToSign() public view returns(uint)
    function getSuggestionValidators(uint withdrawIndex, uint suggestIndex) public view returns (address[] memory)
    function getSuggestionSigHashs(uint withdrawIndex, uint suggestIndex) public view returns (bytes32[] memory)
    function getSignatureHash(uint withdrawIndex, address validator) public view returns (bytes32)

Last updated