aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <i@gavwood.com>2014-01-20 22:53:02 +0800
committerGav Wood <i@gavwood.com>2014-01-20 22:53:02 +0800
commita08ce2bde1ea3f7650251e96c62389166972a249 (patch)
treeb5c06fa2bedb4378cf5cbcfbef8cc415f925e91e
parent6eafb9e6f8ff3cd5520bdba953d69ea789a74a30 (diff)
downloaddexon-solidity-a08ce2bde1ea3f7650251e96c62389166972a249.tar
dexon-solidity-a08ce2bde1ea3f7650251e96c62389166972a249.tar.gz
dexon-solidity-a08ce2bde1ea3f7650251e96c62389166972a249.tar.bz2
dexon-solidity-a08ce2bde1ea3f7650251e96c62389166972a249.tar.lz
dexon-solidity-a08ce2bde1ea3f7650251e96c62389166972a249.tar.xz
dexon-solidity-a08ce2bde1ea3f7650251e96c62389166972a249.tar.zst
dexon-solidity-a08ce2bde1ea3f7650251e96c62389166972a249.zip
Various fixes.
-rw-r--r--CMakeLists.txt2
-rw-r--r--crypto.cpp17
-rw-r--r--main.cpp2
-rw-r--r--state.cpp31
4 files changed, 32 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e9e46411..7e2d1ca8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,3 +17,5 @@ target_link_libraries(testeth ethereum)
target_link_libraries(testeth cryptopp)
target_link_libraries(testeth secp256k1)
target_link_libraries(testeth gmp)
+target_link_libraries(testeth boost_system)
+target_link_libraries(testeth boost_filesystem)
diff --git a/crypto.cpp b/crypto.cpp
index 0c9f9e35..75ac9e91 100644
--- a/crypto.cpp
+++ b/crypto.cpp
@@ -34,8 +34,16 @@ int cryptoTest()
bytes tx = fromUserHex("88005401010101010101010101010101010101010101011f0de0b6b3a76400001ce8d4a5100080181c373130a009ba1f10285d4e659568bfcfec85067855c5a3c150100815dad4ef98fd37cf0593828c89db94bd6c64e210a32ef8956eaa81ea9307194996a3b879441f5d");
cout << "TX: " << RLP(tx) << endl;
- Transaction t(tx);
- cout << "SENDER: " << hex << t.sender() << endl;
+ Transaction t2(tx);
+ cout << "SENDER: " << hex << t2.sender() << endl;
+
+ secp256k1_start();
+
+ Transaction t;
+ t.nonce = 0;
+ t.fee = 0;
+ t.value = 1; // 1 wei.
+ t.receiveAddress = toAddress(sha3("123"));
bytes sig64 = toBigEndian(t.vrs.r) + toBigEndian(t.vrs.s);
cout << "SIG: " << sig64.size() << " " << asHex(sig64) << " " << t.vrs.v << endl;
@@ -48,8 +56,6 @@ int cryptoTest()
bytes privkey = sha3Bytes("123");
- secp256k1_start();
-
{
bytes pubkey(65);
int pubkeylen = 65;
@@ -68,6 +74,9 @@ int cryptoTest()
bytes sig(64);
u256 nonce = 0;
int v = 0;
+ cout << asHex(hmsg) << endl;
+ cout << asHex(privkey) << endl;
+ cout << hex << nonce << endl;
int ret = secp256k1_ecdsa_sign_compact((byte const*)hmsg.data(), hmsg.size(), sig.data(), privkey.data(), (byte const*)&nonce, &v);
cout << "MYSIG: " << dec << ret << " " << sig.size() << " " << asHex(sig) << " " << v << endl;
diff --git a/main.cpp b/main.cpp
index 994b611f..ff2be2a5 100644
--- a/main.cpp
+++ b/main.cpp
@@ -35,7 +35,7 @@ int main()
rlpTest();
trieTest();
// daggerTest();
-// cryptoTest();
+ cryptoTest();
stateTest();
return 0;
}
diff --git a/state.cpp b/state.cpp
index c4c148b4..517e1d5d 100644
--- a/state.cpp
+++ b/state.cpp
@@ -20,43 +20,44 @@
* State test functions.
*/
+#include <secp256k1.h>
+#include <BlockChain.h>
#include <State.h>
using namespace std;
using namespace eth;
-struct KeyPair
-{
- KeyPair() {}
- KeyPair(PrivateKey _k): priv(_k), addr(toPublic(_k)) {}
- PrivateKey priv;
- Address addr;
-};
-
int stateTest()
{
KeyPair me = sha3("Gav Wood");
KeyPair myMiner = sha3("Gav's Miner");
// KeyPair you = sha3("123");
- State s(myMiner.addr);
+ BlockChain bc("/tmp");
+ State s(myMiner.address(), "/tmp");
// Mine to get some ether!
- s.mine();
+ s.commitToMine(bc);
+ while (!s.mine(100)) {}
+ bc.attemptImport(s.blockData());
+ s.sync(bc);
bytes tx;
{
Transaction t;
- t.nonce = s.transactionsFrom(myMiner.addr);
+ t.nonce = s.transactionsFrom(myMiner.address());
t.fee = 0;
- t.value = 1; // 1 wei.
- t.receiveAddress = me.addr;
- t.sign(myMiner.priv);
+ t.value = 1000000000; // 1e9 wei.
+ t.receiveAddress = me.address();
+ t.sign(myMiner.secret());
tx = t.rlp();
}
cout << RLP(tx) << endl;
s.execute(tx);
- // TODO: Mine to set in stone.
+ s.commitToMine(bc);
+ while (!s.mine(100)) {}
+ bc.attemptImport(s.blockData());
+ s.sync(bc);
return 0;
}