Created
August 31, 2018 19:49
-
-
Save juntao/3962cc917d395c089d5af6db83a21f9a 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
var sortloopsABI = [{"constant":true,"inputs":[{"name":"x","type":"uint256"}],"name":"sort","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"pure","type":"function"}]; | |
var sortloopsBC = '0x608060405234801561001057600080fd5b506101f0806100206000396000f300608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063fe91386514610046575b600080fd5b34801561005257600080fd5b50610071600480360381019080803590602001909291905050506100ec565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b1578082015181840152602081019050610096565b50505050905090810190601f1680156100de5780820d805160018360200d6101000a0d1916815260200191505b509250505060405180910390f35b60608060405160206040519081016040526001905260206040519081016040527f0900000000000000000000000000000000000000000000000000000000000000905260206040519081016040526001905260206040519081016040527f04000000000000000000000000000000000000000000000000000000000000009052602060405190810160405280600090528460206040519081016040525280604051819003602090039052907f736f727400000000000000000000000000000000000000000000000000000000f59050809150509190505600a165627a7a72305820f27016a8e33bd1c5e981b60bf098491e2e562329ac25fdf5696bf0aaed90bf640029'; | |
var sortloopsContract = web3.cmt.contract(sortloopsABI); | |
var sortloops = sortloopsContract.new( | |
{ | |
from: web3.cmt.accounts[0], | |
data: sortloopsBC, | |
gas: '4700000' | |
}, function (e, contract){ | |
console.log(e, contract); | |
if (typeof contract.address !== 'undefined') { | |
console.log('Contract mined! address: ' + contract.address + ' 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 Sort : public eni::EniBase | |
{ | |
public: | |
Sort(const std::string& pArgStr) : eni::EniBase(pArgStr) { } | |
~Sort() { } | |
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 arr[10] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; | |
eni::Int sum = 0; | |
for(eni::Int k=0;k<x;k++){ | |
bool swapped=false; | |
for(int i=0; i<sizeof(arr)-1; i++){ | |
for(int j=0; j<sizeof(arr)-1-i; j++){ | |
if(arr[j]>arr[i]){ | |
eni::Int temp=arr[j]; | |
arr[j]=arr[j+1]; | |
arr[j+1]=temp; | |
swapped=true; | |
} | |
} | |
if(!swapped) break; | |
} | |
swapped=false; | |
for(int i=0; i<sizeof(arr)-1; i++){ | |
for(int j=0; j<sizeof(arr)-1-i; j++){ | |
if(arr[j]<arr[i]){ | |
eni::Int temp=arr[j]; | |
arr[j]=arr[j+1]; | |
arr[j+1]=temp; | |
swapped=true; | |
} | |
} | |
if(!swapped) break; | |
} | |
} | |
sum = sum + sizeof(arr); | |
std::string s=boost::lexical_cast<std::string>(sum); | |
pRetVal.emplace_back(s); | |
return true; | |
} | |
private: | |
eni::Int x; | |
}; | |
ENI_C_INTERFACE(sort, Sort) |
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
> sortloops.sort(9000); | |
Error: new BigNumber() not a base 16 number: | |
at raise (web3-cmt.js:16843:29) | |
at web3-cmt.js:16831:33 | |
at BigNumber (web3-cmt.js:15865:28) | |
at web3-cmt.js:9439:23 | |
at web3-cmt.js:9963:20 | |
at web3-cmt.js:9155:16 | |
at map (<native code>) | |
at web3-cmt.js:9154:12 | |
at web3-cmt.js:12391:18 |
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
CPPFLAGS=-I/home/ubuntu/libeni/include | |
CXXFLAGS=-std=c++11 -fPIC | |
LDFLAGS=-L/home/ubuntu/libeni/lib | |
LDADD=-leni | |
all: | |
g++ ${CPPFLAGS} ${CXXFLAGS} ${LDFLAGS} -shared -oeni_sort.so eni_sort.cpp ${LDADD} |
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 sortloops { | |
function sort(uint256 x) public pure returns(string) { | |
string memory sum; | |
sum=eni("sort", x); | |
return sum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment