Skip to content

Instantly share code, notes, and snippets.

@siman
Last active November 2, 2017 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siman/57d1b7c96770201b5e8c5e5774082565 to your computer and use it in GitHub Desktop.
Save siman/57d1b7c96770201b5e8c5e5774082565 to your computer and use it in GitHub Desktop.
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment