Created
August 31, 2018 04:11
-
-
Save juntao/7a4a789d0f1cafbbbf67e6c05a59a279 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.23; | |
contract addloops { | |
function add(uint256 x) public pure returns(string) { | |
string memory sum; | |
sum=eni("add", x); | |
return sum; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> bytecode="608060405234801561001057600080fd5b506101f0806100206000396000f300608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631003e2d214610046575b600080fd5b34801561005257600080fd5b50610071600480360381019080803590602001909291905050506100ec565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b1578082015181840152602081019050610096565b50505050905090810190601f1680156100de5780820d805160018360200d6101000a0d1916815260200191505b509250505060405180910390f35b60608060405160206040519081016040526001905260206040519081016040527f0900000000000000000000000000000000000000000000000000000000000000905260206040519081016040526001905260206040519081016040527f04000000000000000000000000000000000000000000000000000000000000009052602060405190810160405280600090528460206040519081016040525280604051819003602090039052907f6164640000000000000000000000000000000000000000000000000000000000f59050809150509190505600a165627a7a72305820287012d49379416e8186fadde599b1053ab8d564531088a2b09b02d9d3ba48ec0029" | |
> abi = [{"constant":true,"inputs":[{"name":"x","type":"uint256"}],"name":"add","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"pure","type":"function"}] | |
> contract = web3.cmt.contract(abi); | |
> contractInstance = contract.new( | |
{ | |
from: web3.cmt.accounts[0], | |
data: bytecode, | |
gas: "4700000" | |
}, | |
function(e, contract) { | |
console.log("contract address: " + contract.address); | |
console.log("transactionHash: " + contract.transactionHash); | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <eni.h> | |
#include <string> | |
class Addition : public eni::EniBase | |
{ | |
public: | |
Addition(const std::string& pArgStr) : eni::EniBase(pArgStr) { } | |
~Addition() { } | |
private: | |
bool parse(const json::Array& pArgs) override { | |
x = pArgs[0].toInteger(); | |
return true; | |
} | |
eni::Gas gas() const override { | |
return 10000; | |
} | |
bool run(json::Array& pRetVal) override { | |
eni::Int sum = 0; | |
for(eni::Int i=0;i<x;i++){ | |
sum = sum + i; | |
} | |
std::string s=boost::lexical_cast<std::string>(sum); | |
pRetVal.emplace_back(s); | |
return true; | |
} | |
private: | |
eni::Int x; | |
}; | |
ENI_C_INTERFACE(add, Addition) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment