siman
11/2/2017 - 6:23 AM

ExternalTxArray.sol

pragma solidity ^0.4.16;

contract ExternalTx {
    
    enum Currency { BTC, LTC, DASH, ZEC, WAVES, USD, EUR }
    
    // currency_code => (tx_hash => tokens)
    mapping (uint8 => mapping (bytes32 => uint256) ) public txs;
    
    function externalSales(
        uint8[] _currencies, 
        bytes32[] _txIdSha3, 
        uint256[] _tokensE18
    ) public {
        for (uint i = 0; i < _txIdSha3.length; i++) {
            externalTxSha3(Currency(_currencies[i]), _txIdSha3[i], _tokensE18[i]);
        }
    }
    
    function externalTx(
        Currency _currency, 
        string _txId,
        uint256 _tokensE18
    ) internal {
        externalTxSha3(_currency, keccak256(_txId), _tokensE18);
    }
    
    function externalTxSha3(
        Currency _currency, 
        bytes32 _txIdSha3, // To get bytes32 use keccak256(txId)
        uint256 _tokensE18
    ) internal {
        var txsByCur = txs[uint8(_currency)];
        require(txsByCur[_txIdSha3] == 0);
        txsByCur[_txIdSha3] = _tokensE18;
        
        // TODO add USD cents to totals and update counters.
    }
    
    function tokensByTx(uint8 _currency, string _txId) public constant returns (uint256 tokens) {
        return txs[uint8(_currency)][keccak256(_txId)];
    }

    // Deprecated -------
    
    function getBtcCode() public constant returns(uint8) {
        return uint8(Currency.BTC);
    }
    
    function getLtcCode() public constant returns (uint8) {
        return uint8(Currency.LTC);
    }
    
    function getDashCode() public constant returns (uint8) {
        return uint8(Currency.DASH);
    }
    
    function getZecCode() public constant returns (uint8) {
        return uint8(Currency.ZEC);
    }
}