Skip to content

Commit cdc75c9

Browse files
committed
fix contract extension file matching
1 parent b32cef9 commit cdc75c9

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

lib/contracts/compiler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class Compiler {
3232
function (extension, compiler, callback) {
3333
// TODO: warn about files it doesn't know how to compile
3434
let matchingFiles = contractFiles.filter(function (file) {
35-
return (file.filename.match(/\.[0-9a-z]+$/)[0] === extension);
35+
let fileMatch = file.filename.match(/\.[0-9a-z]+$/);
36+
return (fileMatch && (fileMatch[0] === extension));
3637
});
3738

3839
compiler.call(compiler, matchingFiles || [], function (err, compileResult) {
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// https://github.com/nexusdev/erc20/blob/master/contracts/base.sol
2+
3+
pragma solidity ^0.4.2;
4+
contract Token {
5+
6+
event Transfer(address indexed from, address indexed to, uint value);
7+
event Approval( address indexed owner, address indexed spender, uint value);
8+
9+
mapping( address => uint ) _balances;
10+
mapping( address => mapping( address => uint ) ) _approvals;
11+
uint public _supply;
12+
//uint public _supply2;
13+
function Token( uint initial_balance ) {
14+
_balances[msg.sender] = initial_balance;
15+
_supply = initial_balance;
16+
}
17+
function totalSupply() constant returns (uint supply) {
18+
return _supply;
19+
}
20+
function balanceOf( address who ) constant returns (uint value) {
21+
return _balances[who];
22+
}
23+
function transfer( address to, uint value) returns (bool ok) {
24+
if( _balances[msg.sender] < value ) {
25+
throw;
26+
}
27+
if( !safeToAdd(_balances[to], value) ) {
28+
throw;
29+
}
30+
_balances[msg.sender] -= value;
31+
_balances[to] += value;
32+
Transfer( msg.sender, to, value );
33+
return true;
34+
}
35+
function transferFrom( address from, address to, uint value) returns (bool ok) {
36+
// if you don't have enough balance, throw
37+
if( _balances[from] < value ) {
38+
throw;
39+
}
40+
// if you don't have approval, throw
41+
if( _approvals[from][msg.sender] < value ) {
42+
throw;
43+
}
44+
if( !safeToAdd(_balances[to], value) ) {
45+
throw;
46+
}
47+
// transfer and return true
48+
_approvals[from][msg.sender] -= value;
49+
_balances[from] -= value;
50+
_balances[to] += value;
51+
Transfer( from, to, value );
52+
return true;
53+
}
54+
function approve(address spender, uint value) returns (bool ok) {
55+
// TODO: should increase instead
56+
_approvals[msg.sender][spender] = value;
57+
Approval( msg.sender, spender, value );
58+
return true;
59+
}
60+
function allowance(address owner, address spender) constant returns (uint _allowance) {
61+
return _approvals[owner][spender];
62+
}
63+
function safeToAdd(uint a, uint b) internal returns (bool) {
64+
return (a + b >= a);
65+
}
66+
}

0 commit comments

Comments
 (0)