mirror of https://github.com/embarklabs/embark.git
add supprot for serpent
This commit is contained in:
parent
467713fe87
commit
59d42104b0
|
@ -20,7 +20,7 @@ Compiler.prototype.init = function(env) {
|
|||
console.log("address is : " + primaryAddress);
|
||||
};
|
||||
|
||||
Compiler.prototype.compile = function(contractFile) {
|
||||
Compiler.prototype.compile_solidity = function(contractFile) {
|
||||
var cmd, result, output, json, compiled_object;
|
||||
|
||||
cmd = "solc --input-file " + contractFile + " --combined-json binary,json-abi";
|
||||
|
@ -45,6 +45,52 @@ Compiler.prototype.compile = function(contractFile) {
|
|||
}
|
||||
|
||||
return compiled_object;
|
||||
}
|
||||
|
||||
Compiler.prototype.compile_serpent = function(contractFile) {
|
||||
var cmd, result, output, json, compiled_object;
|
||||
|
||||
cmd = "serpent compile " + contractFile;
|
||||
|
||||
result = exec(cmd, {silent: true});
|
||||
code = result.output;
|
||||
|
||||
if (result.code === 1) {
|
||||
throw new Error(result.output);
|
||||
}
|
||||
|
||||
cmd = "serpent mk_full_signature " + contractFile;
|
||||
result = exec(cmd, {silent: true});
|
||||
|
||||
if (result.code === 1) {
|
||||
throw new Error(result.output);
|
||||
}
|
||||
|
||||
json = JSON.parse(result.output.trim());
|
||||
className = contractFile.split('.')[0].split("/").pop();
|
||||
|
||||
compiled_object = {}
|
||||
compiled_object[className] = {};
|
||||
compiled_object[className].code = code.trim();
|
||||
compiled_object[className].info = {};
|
||||
compiled_object[className].info.abiDefinition = json;
|
||||
|
||||
return compiled_object;
|
||||
}
|
||||
|
||||
|
||||
Compiler.prototype.compile = function(contractFile) {
|
||||
var extension = contractFile.split('.')[1];
|
||||
|
||||
if (extension === 'sol') {
|
||||
return this.compile_solidity(contractFile);
|
||||
}
|
||||
else if (extension === 'se') {
|
||||
return this.compile_serpent(contractFile);
|
||||
}
|
||||
else {
|
||||
throw new Error("extension not known");
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Compiler;
|
||||
|
|
|
@ -33,5 +33,36 @@ describe('embark.compiler', function() {
|
|||
|
||||
});
|
||||
|
||||
describe('compile a serpent file', function() {
|
||||
var files = [
|
||||
'test/support/contracts/cash.se'
|
||||
];
|
||||
|
||||
it("should build a correct compiled object", function() {
|
||||
var compiler = new Compiler();
|
||||
|
||||
var compiledFile = compiler.compile(files[0]);
|
||||
|
||||
assert.equal(compiledFile.cash.code, '6000603f536a0186a000000000000000006040604059905901600090526000815232816020015280905020556103658061003a60003961039f56600061047f537c010000000000000000000000000000000000000000000000000000000060003504638357984f81141561005f57600435604052604060405990590160009052600081526040518160200152809050205460605260206060f35b63693200ce8114156101465760043560a05260243560c0523260e0526040604059905901600090526000815260e051816020015280905020546101005260c051610100511215156101385760c0516040604059905901600090526000815260e05181602001528090502054036040604059905901600090526000815260e0518160200152809050205560c0516040604059905901600090526000815260a05181602001528090502054016040604059905901600090526000815260a0518160200152809050205560c0516101c05260206101c0f3610145565b60006101e05260206101e0f35b5b6380b97fc081141561024c5760043560a05260243560c05260443561020052326102005114151561017e576000610220526020610220f35b6040604059905901600090526000815261020051816020015280905020546101005260c0516101005112151561023e5760c0516040604059905901600090526000815261020051816020015280905020540360406040599059016000905260008152610200518160200152809050205560c0516040604059905901600090526000815260a05181602001528090502054016040604059905901600090526000815260a0518160200152809050205560c0516102e05260206102e0f361024b565b6000610300526020610300f35b5b634c764abc8114156102b4576004356103205260243561034052610340516040604059905901600090526000815261032051816020015280905020540360406040599059016000905260008152610320518160200152809050205560016103a05260206103a0f35b63a92c9b8381141561031c57600435610320526024356103405261034051604060405990590160009052600081526103205181602001528090502054016040604059905901600090526000815261032051816020015280905020556001610400526020610400f35b631d62e92281141561036357600435604052602435610420526104205160406040599059016000905260008152604051816020015280905020556001610460526020610460f35b505b6000f3');
|
||||
|
||||
assert.equal(JSON.stringify(compiledFile.cash.info.abiDefinition), '[{\"name\":\"addCash(int256,int256)\",\"type\":\"function\",\"inputs\":[{\"name\":\"ID\",\"type\":\"int256\"},{\"name\":\"amount\",\"type\":\"int256\"}],\"outputs\":[{\"name\":\"out\",\"type\":\"int256\"}]},{\"name\":\"balance(int256)\",\"type\":\"function\",\"inputs\":[{\"name\":\"address\",\"type\":\"int256\"}],\"outputs\":[{\"name\":\"out\",\"type\":\"int256\"}]},{\"name\":\"send(int256,int256)\",\"type\":\"function\",\"inputs\":[{\"name\":\"recver\",\"type\":\"int256\"},{\"name\":\"value\",\"type\":\"int256\"}],\"outputs\":[{\"name\":\"out\",\"type\":\"int256\"}]},{\"name\":\"sendFrom(int256,int256,int256)\",\"type\":\"function\",\"inputs\":[{\"name\":\"recver\",\"type\":\"int256\"},{\"name\":\"value\",\"type\":\"int256\"},{\"name\":\"from\",\"type\":\"int256\"}],\"outputs\":[{\"name\":\"out\",\"type\":\"int256\"}]},{\"name\":\"setCash(int256,int256)\",\"type\":\"function\",\"inputs\":[{\"name\":\"address\",\"type\":\"int256\"},{\"name\":\"balance\",\"type\":\"int256\"}],\"outputs\":[{\"name\":\"out\",\"type\":\"int256\"}]},{\"name\":\"subtractCash(int256,int256)\",\"type\":\"function\",\"inputs\":[{\"name\":\"ID\",\"type\":\"int256\"},{\"name\":\"amount\",\"type\":\"int256\"}],\"outputs\":[{\"name\":\"out\",\"type\":\"int256\"}]}]');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('compile a file with an error', function() {
|
||||
var files = [
|
||||
'test/support/contracts/error.sol'
|
||||
];
|
||||
|
||||
it("throw an error", function() {
|
||||
var compiler = new Compiler();
|
||||
|
||||
assert.throws(function() { compiler.compile(files[0]) }, Error);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
# This software (Augur) allows buying && selling event outcomes in ethereum
|
||||
# Copyright (C) 2015 Forecast Foundation
|
||||
# This program is free software; you can redistribute it &&/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is free software: you can redistribute it &&/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# Any questions please contact joey@augur.net
|
||||
|
||||
data cashcoinBalances[]
|
||||
|
||||
def init():
|
||||
# test initial funds
|
||||
self.cashcoinBalances[tx.origin] = 100000*2^64
|
||||
|
||||
# @return: cash balance of address
|
||||
def balance(address):
|
||||
return(self.cashcoinBalances[address])
|
||||
|
||||
# should send values as fixed point in UI (1 is 2^64, 4 is 4*2^64, .5 is 2^63, etc.)
|
||||
# so cashcoin fees could just go to root branch, or we could not have fees besides
|
||||
# gas fee to do a send transaction
|
||||
# @return: value sent, 0 if fails
|
||||
def send(recver, value):
|
||||
sender = tx.origin
|
||||
senderBalance = self.cashcoinBalances[sender]
|
||||
if(senderBalance >= value):
|
||||
self.cashcoinBalances[sender] -= value
|
||||
self.cashcoinBalances[recver] += value
|
||||
return(value)
|
||||
else:
|
||||
return(0)
|
||||
|
||||
# @return value of cash sent; fail is 0
|
||||
def sendFrom(recver, value, from):
|
||||
if(from!=tx.origin):
|
||||
return(0)
|
||||
senderBalance = self.cashcoinBalances[from]
|
||||
if(senderBalance >= value):
|
||||
self.cashcoinBalances[from] -= value
|
||||
self.cashcoinBalances[recver] += value
|
||||
return(value)
|
||||
else:
|
||||
return(0)
|
||||
|
||||
# make sure only coming from specific contracts
|
||||
def subtractCash(ID, amount):
|
||||
#if(!self.whitelist.check(msg.sender)):
|
||||
# return(-1)
|
||||
self.cashcoinBalances[ID] -= amount
|
||||
return(1)
|
||||
|
||||
def addCash(ID, amount):
|
||||
#if(!self.whitelist.check(msg.sender)):
|
||||
# return(-1)
|
||||
self.cashcoinBalances[ID] += amount
|
||||
return(1)
|
||||
|
||||
def setCash(address, balance):
|
||||
#if !self.whitelist.check(msg.sender):
|
||||
# return(-1)
|
||||
self.cashcoinBalances[address] = balance
|
||||
return(1)
|
Loading…
Reference in New Issue