ethereum 0.4.42 → 0.4.45

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3986c000b0d2fc54c468722b662b9cbdb605c6a8
4
- data.tar.gz: 3d651b3bfbb3026c64ff72adee2dbc370509b752
3
+ metadata.gz: ce81f0ccd33fa2df00f5fba597d86078e2741ad9
4
+ data.tar.gz: 172e0bc070a39588a23e2eca4297f50bebc49cfc
5
5
  SHA512:
6
- metadata.gz: 8de795387db248cb204a2be8159e9fe7ef7528870babeed5fd5815dd3a321449d1a59c507d7ddeb205be37e92f5359bc16424dd7a2fa1689d3f62590341f0752
7
- data.tar.gz: d41a91a0139ab397228ea0bc16027ea8062a9e2fd4816b96686259f158c08529c3c003f7bbdf2dd405722dbbffc18f4af7b4bb716a486f4b48ffbb2d5c7a8b19
6
+ metadata.gz: 63056e204033d1a0606a685ea5097200527fddb3529c592626e2cd2bf70c050d1cc4619c7cf55988783d8fe50d7dea97ff2b55d329eb6ea47c1f50decf6726f4
7
+ data.tar.gz: 77646073740221587848ba6ea950bb651c1a6c0f847bf3901a26e2548813e323a97093b7e2862403f27c21a00535c754177cbfde129c19c91f7ee6ecbd4dc35c
@@ -0,0 +1,112 @@
1
+ // Accounting v0.1
2
+
3
+ /// @title Accounting Lib - Accounting utilities
4
+ /// @author Piper Merriam - <pipermerriam@gmail.com>
5
+ library AccountingLib {
6
+ struct Bank {
7
+ mapping (address => uint) accountBalances;
8
+ }
9
+
10
+ /// @dev Low level method for adding funds to an account. Protects against overflow.
11
+ /// @param self The Bank instance to operate on.
12
+ /// @param accountAddress The address of the account the funds should be added to.
13
+ /// @param value The amount that should be added to the account.
14
+ function addFunds(Bank storage self, address accountAddress, uint value) public {
15
+ /*
16
+ * Helper function that should be used for any addition of
17
+ * account funds. It has error checking to prevent
18
+ * overflowing the account balance.
19
+ */
20
+ if (self.accountBalances[accountAddress] + value < self.accountBalances[accountAddress]) {
21
+ // Prevent Overflow.
22
+ throw;
23
+ }
24
+ self.accountBalances[accountAddress] += value;
25
+ }
26
+
27
+ event _Deposit(address indexed _from, address indexed accountAddress, uint value);
28
+
29
+ /// @dev Function wrapper around the _Deposit event so that it can be used by contracts. Can be used to log a deposit to an account.
30
+ /// @param _from The address that deposited the funds.
31
+ /// @param accountAddress The address of the account the funds were added to.
32
+ /// @param value The amount that was added to the account.
33
+ function Deposit(address _from, address accountAddress, uint value) public {
34
+ _Deposit(_from, accountAddress, value);
35
+ }
36
+
37
+ /// @dev Safe function for depositing funds. Returns boolean for whether the deposit was successful
38
+ /// @param self The Bank instance to operate on.
39
+ /// @param accountAddress The address of the account the funds should be added to.
40
+ /// @param value The amount that should be added to the account.
41
+ function deposit(Bank storage self, address accountAddress, uint value) public returns (bool) {
42
+ /*
43
+ * Public API for depositing funds in a specified account.
44
+ */
45
+ if (self.accountBalances[accountAddress] + value < self.accountBalances[accountAddress]) {
46
+ return false;
47
+ }
48
+ addFunds(self, accountAddress, value);
49
+ return true;
50
+ }
51
+
52
+ event _Withdrawal(address indexed accountAddress, uint value);
53
+
54
+ /// @dev Function wrapper around the _Withdrawal event so that it can be used by contracts. Can be used to log a withdrawl from an account.
55
+ /// @param accountAddress The address of the account the funds were withdrawn from.
56
+ /// @param value The amount that was withdrawn to the account.
57
+ function Withdrawal(address accountAddress, uint value) public {
58
+ _Withdrawal(accountAddress, value);
59
+ }
60
+
61
+ event _InsufficientFunds(address indexed accountAddress, uint value, uint balance);
62
+
63
+ /// @dev Function wrapper around the _InsufficientFunds event so that it can be used by contracts. Can be used to log a failed withdrawl from an account.
64
+ /// @param accountAddress The address of the account the funds were to be withdrawn from.
65
+ /// @param value The amount that was attempted to be withdrawn from the account.
66
+ /// @param balance The current balance of the account.
67
+ function InsufficientFunds(address accountAddress, uint value, uint balance) public {
68
+ _InsufficientFunds(accountAddress, value, balance);
69
+ }
70
+
71
+ /// @dev Low level method for removing funds from an account. Protects against underflow.
72
+ /// @param self The Bank instance to operate on.
73
+ /// @param accountAddress The address of the account the funds should be deducted from.
74
+ /// @param value The amount that should be deducted from the account.
75
+ function deductFunds(Bank storage self, address accountAddress, uint value) public {
76
+ /*
77
+ * Helper function that should be used for any reduction of
78
+ * account funds. It has error checking to prevent
79
+ * underflowing the account balance which would be REALLY bad.
80
+ */
81
+ if (value > self.accountBalances[accountAddress]) {
82
+ // Prevent Underflow.
83
+ throw;
84
+ }
85
+ self.accountBalances[accountAddress] -= value;
86
+ }
87
+
88
+ /// @dev Safe function for withdrawing funds. Returns boolean for whether the deposit was successful as well as sending the amount in ether to the account address.
89
+ /// @param self The Bank instance to operate on.
90
+ /// @param accountAddress The address of the account the funds should be withdrawn from.
91
+ /// @param value The amount that should be withdrawn from the account.
92
+ function withdraw(Bank storage self, address accountAddress, uint value) public returns (bool) {
93
+ /*
94
+ * Public API for withdrawing funds.
95
+ */
96
+ if (self.accountBalances[accountAddress] >= value) {
97
+ deductFunds(self, accountAddress, value);
98
+ if (!accountAddress.send(value)) {
99
+ // Potentially sending money to a contract that
100
+ // has a fallback function. So instead, try
101
+ // tranferring the funds with the call api.
102
+ if (!accountAddress.call.value(value)()) {
103
+ // Revert the entire transaction. No
104
+ // need to destroy the funds.
105
+ //throw;
106
+ }
107
+ }
108
+ return true;
109
+ }
110
+ return false;
111
+ }
112
+ }
@@ -0,0 +1,59 @@
1
+ import "contracts/AccountingLib.sol";
2
+
3
+ contract TestAccounting {
4
+ AccountingLib.Bank bank;
5
+ /*
6
+ * Account Management API
7
+ */
8
+ function getAccountBalance(address accountAddress) constant public returns (uint) {
9
+ return bank.accountBalances[accountAddress];
10
+ }
11
+
12
+ function deposit() public {
13
+ deposit(msg.sender);
14
+ }
15
+
16
+ function deposit(address accountAddress) public {
17
+ /*
18
+ * Public API for depositing funds in a specified account.
19
+ */
20
+ AccountingLib.deposit(bank, accountAddress, msg.value);
21
+ AccountingLib.Deposit(msg.sender, accountAddress, msg.value);
22
+ }
23
+
24
+ function addFunds(uint value) public {
25
+ addFunds(msg.sender, value);
26
+ }
27
+
28
+ function addFunds(address accountAddress, uint value) public {
29
+ AccountingLib.addFunds(bank, accountAddress, value);
30
+ }
31
+
32
+ function withdraw(uint value) public {
33
+ /*
34
+ * Public API for withdrawing funds.
35
+ */
36
+ if (AccountingLib.withdraw(bank, msg.sender, value)) {
37
+ AccountingLib.Withdrawal(msg.sender, value);
38
+ }
39
+ else {
40
+ AccountingLib.InsufficientFunds(msg.sender, value, bank.accountBalances[msg.sender]);
41
+ }
42
+ }
43
+
44
+ function deductFunds(uint value) public {
45
+ deductFunds(msg.sender, value);
46
+ }
47
+
48
+ function deductFunds(address accountAddress, uint value) public {
49
+ AccountingLib.deductFunds(bank, accountAddress, value);
50
+ }
51
+
52
+ function setAccountBalance(uint value) public {
53
+ setAccountBalance(msg.sender, value);
54
+ }
55
+
56
+ function setAccountBalance(address accountAddress, uint value) public {
57
+ bank.accountBalances[accountAddress] = value;
58
+ }
59
+ }
@@ -16,4 +16,6 @@ module Ethereum
16
16
  require 'ethereum/formatter'
17
17
  require 'ethereum/transaction'
18
18
  require 'ethereum/deployment'
19
+ require 'ethereum/project_initializer'
20
+ require 'ethereum/contract_initializer'
19
21
  end
@@ -30,11 +30,13 @@ module Ethereum
30
30
  end
31
31
 
32
32
  define_method :deploy do |*params|
33
- raise "Missing constructor parameter" and return if params.length != constructor_inputs.length
34
33
  formatter = Ethereum::Formatter.new
35
- constructor_inputs.each_index do |i|
36
- args = [constructor_inputs[i]["type"], params[i]]
37
- code << formatter.to_payload(args)
34
+ if constructor_inputs.present?
35
+ raise "Missing constructor parameter" and return if params.length != constructor_inputs.length
36
+ constructor_inputs.each_index do |i|
37
+ args = [constructor_inputs[i]["type"], params[i]]
38
+ code << formatter.to_payload(args)
39
+ end
38
40
  end
39
41
  deploytx = connection.send_transaction({from: self.sender, gas: 2000000, gasPrice: 60000000000, data: code})["result"]
40
42
  self.instance_variable_set("@deployment", Ethereum::Deployment.new(deploytx, connection))
@@ -0,0 +1,39 @@
1
+ module Ethereum
2
+
3
+ class ContractInitializer
4
+
5
+ attr_accessor :abi, :binary, :name, :libraries, :needs_linking
6
+
7
+ def initialize(contract_name, contract)
8
+ @abi = JSON.parse(contract["abi"]) unless contract.nil?
9
+ @binary = contract["bin"] unless contract.nil?
10
+ @name = contract_name
11
+ matchdata = /_+[a-zA-Z]+_+/.match(@binary)
12
+ @needs_linking = matchdata.present?
13
+ if @needs_linking
14
+ @libraries = matchdata.to_a.collect do |libname|
15
+ {name: libname.gsub(/_+/,''), sigil: libname}
16
+ end
17
+ end
18
+ end
19
+
20
+ def link_libraries
21
+ if @needs_linking
22
+ @libraries.each do |library|
23
+ ENV['ETHEREUM_DEPLOYER_WAIT_TIME'] ||= "120"
24
+ wait_time = ENV['ETHEREUM_DEPLOYER_WAIT_TIME'].to_i
25
+ library_instance = library[:name].constantize.new
26
+ library_instance.deploy_and_wait(wait_time)
27
+ @binary.gsub!(library[:sigil], library_instance.address.gsub(/^0x/,''))
28
+ end
29
+ end
30
+ end
31
+
32
+ def build(connection)
33
+ contract = Ethereum::Contract.new(@name, @binary, @abi)
34
+ contract.build(connection)
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,22 @@
1
+ module Ethereum
2
+
3
+ class ProjectInitializer
4
+
5
+ attr_accessor :contract_names, :combined_output, :contracts
6
+
7
+ def initialize(location)
8
+ ENV['ETHEREUM_SOLIDITY_BINARY'] ||= "/usr/local/bin/solc"
9
+ solidity = ENV['ETHEREUM_SOLIDITY_BINARY']
10
+ contract_dir = location
11
+ compile_command = "#{solidity} --combined-json abi,bin #{contract_dir}"
12
+ raw_data = `#{compile_command}`
13
+ data = JSON.parse(raw_data)
14
+ @contract_names = data["contracts"].keys
15
+ @contracts = @contract_names.collect do |contract_name|
16
+ ContractInitializer.new(contract_name, data["contracts"][contract_name])
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Ethereum
2
- VERSION = "0.4.42"
2
+ VERSION = "0.4.45"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ethereum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.42
4
+ version: 0.4.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - DigixGlobal Pte Ltd (https://dgx.io)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-21 00:00:00.000000000 Z
11
+ date: 2015-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,11 +114,14 @@ files:
114
114
  - Rakefile
115
115
  - bin/console
116
116
  - bin/setup
117
+ - contracts/AccountingLib.sol
118
+ - contracts/Testing.sol
117
119
  - ethereum.gemspec
118
120
  - lib/ethereum.rb
119
121
  - lib/ethereum/client.rb
120
122
  - lib/ethereum/contract.rb
121
123
  - lib/ethereum/contract_event.rb
124
+ - lib/ethereum/contract_initializer.rb
122
125
  - lib/ethereum/deployment.rb
123
126
  - lib/ethereum/formatter.rb
124
127
  - lib/ethereum/function.rb
@@ -127,6 +130,7 @@ files:
127
130
  - lib/ethereum/http_client.rb
128
131
  - lib/ethereum/initializer.rb
129
132
  - lib/ethereum/ipc_client.rb
133
+ - lib/ethereum/project_initializer.rb
130
134
  - lib/ethereum/transaction.rb
131
135
  - lib/ethereum/version.rb
132
136
  homepage: https://github.com/DigixGlobal/ethereum-ruby