-
Notifications
You must be signed in to change notification settings - Fork 70
/
ethereum.ros
138 lines (129 loc) · 3.78 KB
/
ethereum.ros
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
request_funds(1){
find_account{
currency = {"symbol":"ETH", "decimals":18};
random_account = find_balance({
"minimum_balance":{
"value": "0",
"currency": {{currency}}
},
"create_limit":1
});
},
// Create a separate scenario to request funds so that
// the address we are using to request funds does not
// get rolled back if funds do not yet exist.
request{
loaded_account = find_balance({
"account_identifier": {{random_account.account_identifier}},
"minimum_balance":{
"value": "10000000000000000",
"currency": {{currency}}
}
});
}
}
create_account(1){
create{
network = {"network":"Ropsten", "blockchain":"Ethereum"};
key = generate_key({"curve_type": "secp256k1"});
account = derive({
"network_identifier": {{network}},
"public_key": {{key.public_key}}
});
// If the account is not saved, the key will be lost!
save_account({
"account_identifier": {{account.account_identifier}},
"keypair": {{key}}
});
}
}
transfer(10){
transfer{
transfer.network = {"network":"Ropsten", "blockchain":"Ethereum"};
currency = {"symbol":"ETH", "decimals":18};
sender = find_balance({
"minimum_balance":{
"value": "10000000000000000",
"currency": {{currency}}
}
});
// Set the recipient_amount as some value <= sender.balance-max_fee
max_fee = "84000000000000";
available_amount = {{sender.balance.value}} - {{max_fee}};
recipient_amount = random_number({"minimum": "1", "maximum": {{available_amount}}});
print_message({"recipient_amount":{{recipient_amount}}});
// Find recipient and construct operations
sender_amount = 0 - {{recipient_amount}};
recipient = find_balance({
"not_account_identifier":[{{sender.account_identifier}}],
"minimum_balance":{
"value": "0",
"currency": {{currency}}
},
"create_limit": 100,
"create_probability": 50
});
transfer.confirmation_depth = "1";
transfer.operations = [
{
"operation_identifier":{"index":0},
"type":"CALL",
"account":{{sender.account_identifier}},
"amount":{
"value":{{sender_amount}},
"currency":{{currency}}
}
},
{
"operation_identifier":{"index":1},
"type":"CALL",
"account":{{recipient.account_identifier}},
"amount":{
"value":{{recipient_amount}},
"currency":{{currency}}
}
}
];
}
}
return_funds(10){
// TODO: add suggested fee dry run to ensure account fully cleared
transfer{
transfer.network = {"network":"Ropsten", "blockchain":"Ethereum"};
currency = {"symbol":"ETH", "decimals":18};
max_fee = "84000000000000";
sender = find_balance({
"minimum_balance":{
"value": {{max_fee}},
"currency": {{currency}}
}
});
// Set the recipient_amount as some sender.balance-max_fee
available_amount = {{sender.balance.value}} - {{max_fee}};
print_message({"available_amount":{{available_amount}}});
sender_amount = 0 - {{available_amount}};
// Provide a static address as the recipient and construct operations
faucet = {"address":"0xb41B39479a525AB69e38c701A713D98E3074252c"};
transfer.confirmation_depth = "1";
transfer.operations = [
{
"operation_identifier":{"index":0},
"type":"CALL",
"account":{{sender.account_identifier}},
"amount":{
"value":{{sender_amount}},
"currency":{{currency}}
}
},
{
"operation_identifier":{"index":1},
"type":"CALL",
"account":{{faucet}},
"amount":{
"value":{{available_amount}},
"currency":{{currency}}
}
}
];
}
}