-
Notifications
You must be signed in to change notification settings - Fork 4
/
getTheDAOCreatedTokenEventsWithNonZeroExtraBalance_v3
97 lines (83 loc) · 4.08 KB
/
getTheDAOCreatedTokenEventsWithNonZeroExtraBalance_v3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
# ------------------------------------------------------------------------------
# Retrieve The DAO CreatedToken events with non-zero extraBalance amounts.
# These events are from block 1520861 to 1599205 when the creation phase ended.
#
# Usage:
# 1. Download this script to getTheDAOCreatedTokenEventsWithNonZeroExtraBalance .
# 2. `chmod 700 getTheDAOCreatedTokenEventsWithNonZeroExtraBalance`
# 3. Run `geth console` in a window.
# 4. Then run this script `./getTheDAOCreatedTokenEventsWithNonZeroExtraBalance`
# in a separate window.
#
# Enjoy. (c) BokkyPooBah 2016. The MIT licence.
# ------------------------------------------------------------------------------
geth attach << EOF | egrep "Header|Data"
var theDAOABIFragment = [{"anonymous":false,"inputs":[{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"CreatedToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"Transfer","type":"event"}];
var theDAOAddress = "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413";
// Full non-zero extraBalance contributions
var theDAOStartingBlock = 1520861;
var theDAOEndingBlock = 1599205;
// Test
// var theDAOStartingBlock = 1520861;
// var theDAOEndingBlock = 1520861;
// Test - by proxy
// var theDAOStartingBlock = 1599204;
// var theDAOEndingBlock = 1599204;
// Test - directly
// var theDAOStartingBlock = 1521563;
// var theDAOEndingBlock = 1521563;
// Test - wallet contract
// var theDAOStartingBlock = 1547894;
// var theDAOEndingBlock = 1547895;
// Test - Out of gas
// var theDAOStartingBlock = 1594238;
// var theDAOEndingBlock = 1594240;
var theDAO = web3.eth.contract(theDAOABIFragment).at(theDAOAddress);
var theDAOCreatedTokenEvent = theDAO.CreatedToken({}, {fromBlock: theDAOStartingBlock, toBlock: theDAOEndingBlock});
console.log("Header\tFrom\tTokenOwner\tCreatedBy\tBlockNumber\tTxHash\tTimestamp\tGMTDateTime\tAmount\tTheDAOAmount\textraBalanceAmount\tTheDAOTokens\tGasUsed\tGasPrice\tCost\tNonce\tError");
theDAOCreatedTokenEvent.watch(function(error, result){
var tx = eth.getTransaction(result.transactionHash);
var txReceipt = eth.getTransactionReceipt(result.transactionHash);
var gasUsed = txReceipt.gasUsed;
var gasPrice = tx.gasPrice;
var cost = gasUsed * gasPrice;
var amount = tx.value;
// console.log("Data amount: " + amount);
var block = eth.getBlock(tx.blockNumber);
var d = new Date(block.timestamp * 1000);
var status = debug.traceTransaction(result.transactionHash);
var extraBalanceAmount = 0;
var tokenOwner = tx.from;
var createdBy = "Owner";
var error = "";
status.structLogs.forEach(function(e) {
if (e.op == "CALL") {
var stack = e.stack;
extraBalanceAmount = web3.toBigNumber("0x" + stack[stack.length-3]);
// baac5300 = createTokenProxy(address) - https://www.4byte.directory/signatures/?bytes4_signature=0xbaac5300
if (stack[0].substring(56) == "baac5300") {
tokenOwner = "0x" + stack[2].substring(24);
createdBy = "Proxy";
} else if (stack[0].substring(56) == "b61d27f6") {
amount = web3.toBigNumber("0x" + stack[stack.length-3]);
} else if (stack[0].substring(56) == "00000966") {
if (("0x" + stack[3].substring(24)) != tokenOwner) {
tokenOwner = "0x" + stack[3].substring(24);
createdBy = "Wallet Contract";
}
}
}
if (e.error.length > 0) {
error = e.error;
}
});
var theDAOAmount = amount - extraBalanceAmount;
var theDAOTokens = theDAOAmount * 100;
console.log("Data\t" + tx.from + "\t" + tokenOwner + "\t" + createdBy + "\t" + tx.blockNumber + "\t" + tx.hash + "\t" +
block.timestamp + "\t" + d.toGMTString() + "\t" + web3.fromWei(amount, "ether") + "\t" +
web3.fromWei(theDAOAmount, "ether") + "\t" + web3.fromWei(extraBalanceAmount, "ether") + "\t" +
web3.fromWei(theDAOTokens, "ether") + "\t" + gasUsed + "\t" + gasPrice + "\t" +
web3.fromWei(cost, "ether") + "\t" + tx.nonce + "\t" + error);
});
EOF