radiator 0.4.5 → 0.4.8.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +11 -11
- data/Rakefile +50 -20
- data/lib/radiator.rb +3 -1
- data/lib/radiator/api.rb +105 -14
- data/lib/radiator/bridge.rb +34 -0
- data/lib/radiator/chain_config.rb +9 -2
- data/lib/radiator/database_api.rb +1 -1
- data/lib/radiator/follow_api.rb +1 -1
- data/lib/radiator/market_history_api.rb +1 -1
- data/lib/radiator/operation.rb +3 -2
- data/lib/radiator/operation_types.rb +43 -27
- data/lib/radiator/ssc/base_steem_smart_contract_rpc.rb +52 -10
- data/lib/radiator/ssc/blockchain.rb +10 -0
- data/lib/radiator/ssc/contracts.rb +17 -0
- data/lib/radiator/stream.rb +15 -6
- data/lib/radiator/transaction.rb +41 -1
- data/lib/radiator/type/amount.rb +26 -50
- data/lib/radiator/type/beneficiaries.rb +8 -1
- data/lib/radiator/type/price.rb +2 -2
- data/lib/radiator/version.rb +1 -1
- data/radiator.gemspec +15 -13
- data/test/fixtures/empty.json +1 -0
- data/test/fixtures/error.json +29 -0
- data/test/fixtures/follow_api_get_followers.json +1 -0
- data/test/fixtures/get_account.json +165 -0
- data/test/fixtures/get_account_count.json +1 -0
- data/test/fixtures/get_account_references.json +1 -0
- data/test/fixtures/get_block.json +193 -0
- data/test/fixtures/get_dynamic_global_properties.json +32 -0
- data/test/fixtures/get_feed_history.json +684 -0
- data/test/fixtures/get_hardfork_version.json +1 -0
- data/test/fixtures/get_key_references.json +14 -0
- data/test/fixtures/get_stats_for_time.json +57 -0
- data/test/fixtures/get_vesting_delegation.json +936 -0
- data/test/fixtures/golos_get_dynamic_global_properties.json +32 -0
- data/test/fixtures/market_history_api_get_market_history_buckets.json +1 -0
- data/test/fixtures/market_history_api_get_order_book.json +109 -0
- data/test/fixtures/market_history_api_get_recent_trades.json +55 -0
- data/test/fixtures/market_history_api_get_ticker.json +11 -0
- data/test/fixtures/market_history_api_get_volume.json +1 -0
- data/test/fixtures/null.json +1 -0
- data/test/fixtures/vcr_cassettes/account_by_key_api_all_methods.yml +631 -0
- data/test/fixtures/vcr_cassettes/account_by_key_api_jsonrpc.yml +52 -0
- data/test/fixtures/vcr_cassettes/all_methods.yml +18155 -0
- data/test/fixtures/vcr_cassettes/api_all_methods.yml +13419 -0
- data/test/fixtures/vcr_cassettes/base_per_debt.yml +5408 -0
- data/test/fixtures/vcr_cassettes/base_per_mvest.yml +4351 -0
- data/test/fixtures/vcr_cassettes/block_time.yml +3687 -0
- data/test/fixtures/vcr_cassettes/broadcast_transaction.yml +1186 -0
- data/test/fixtures/vcr_cassettes/condenser_all_all_methods.yml +13462 -0
- data/test/fixtures/vcr_cassettes/condenser_api_jsonrpc.yml +51 -0
- data/test/fixtures/vcr_cassettes/expiration_initialize.yml +3997 -0
- data/test/fixtures/vcr_cassettes/find_account.yml +4004 -0
- data/test/fixtures/vcr_cassettes/find_block.yml +3946 -0
- data/test/fixtures/vcr_cassettes/find_comment.yml +12457 -0
- data/test/fixtures/vcr_cassettes/follow_api_jsonrpc.yml +52 -0
- data/test/fixtures/vcr_cassettes/get_account_count.yml +627 -0
- data/test/fixtures/vcr_cassettes/get_account_references.yml +663 -0
- data/test/fixtures/vcr_cassettes/get_accounts.yml +735 -0
- data/test/fixtures/vcr_cassettes/get_accounts_no_argument.yml +663 -0
- data/test/fixtures/vcr_cassettes/get_dynamic_global_properties.yml +721 -0
- data/test/fixtures/vcr_cassettes/get_feed_history.yml +1201 -0
- data/test/fixtures/vcr_cassettes/get_hardfork_version.yml +629 -0
- data/test/fixtures/vcr_cassettes/get_key_references.yml +1091 -0
- data/test/fixtures/vcr_cassettes/get_market_history.yml +1147 -0
- data/test/fixtures/vcr_cassettes/get_market_history_buckets.yml +1147 -0
- data/test/fixtures/vcr_cassettes/get_order_book.yml +1195 -0
- data/test/fixtures/vcr_cassettes/get_recent_trades.yml +1147 -0
- data/test/fixtures/vcr_cassettes/get_ticker.yml +1151 -0
- data/test/fixtures/vcr_cassettes/get_trade_history.yml +1153 -0
- data/test/fixtures/vcr_cassettes/get_vesting_delegations.yml +575 -0
- data/test/fixtures/vcr_cassettes/get_volume.yml +1155 -0
- data/test/fixtures/vcr_cassettes/get_witness_by_account.yml +627 -0
- data/test/fixtures/vcr_cassettes/look_up_witnesses.yml +575 -0
- data/test/fixtures/vcr_cassettes/market_history_api_all_methods.yml +4373 -0
- data/test/fixtures/vcr_cassettes/network_broadcast_api_all_methods.yml +1288 -0
- data/test/fixtures/vcr_cassettes/properties.yml +3992 -0
- data/test/fixtures/vcr_cassettes/recover_transaction.yml +1211 -0
- data/test/fixtures/vcr_cassettes/ssc_blockchain_block_info.yml +92 -0
- data/test/fixtures/vcr_cassettes/ssc_blockchain_block_info_invalid.yml +90 -0
- data/test/fixtures/vcr_cassettes/ssc_blockchain_latest_block_info.yml +91 -0
- data/test/fixtures/vcr_cassettes/ssc_blockchain_transaction_info.yml +92 -0
- data/test/fixtures/vcr_cassettes/ssc_contracts_contract.yml +366 -0
- data/test/fixtures/vcr_cassettes/ssc_contracts_find.yml +91 -0
- data/test/fixtures/vcr_cassettes/ssc_contracts_find_one.yml +89 -0
- data/test/fixtures/vcr_cassettes/stream_jsonrpc.yml +9175 -0
- data/test/fixtures/vcr_cassettes/transaction_expiration_initialize_nil.yml +3743 -0
- data/test/fixtures/vcr_cassettes/transaction_jsonrpc.yml +151 -0
- data/test/fixtures/vcr_cassettes/unknown_chain_id.yml +3869 -0
- data/test/fixtures/vcr_cassettes/valid_chains.yml +3427 -0
- data/test/radiator/account_by_key_api_test.rb +46 -0
- data/test/radiator/api_test.rb +135 -0
- data/test/radiator/chain_stats_api_test.rb +49 -0
- data/test/radiator/chain_test.rb +153 -0
- data/test/radiator/condenser_api_test.rb +48 -0
- data/test/radiator/follow_api_test.rb +48 -0
- data/test/radiator/market_history_api_test.rb +100 -0
- data/test/radiator/network_broadcast_api_test.rb +48 -0
- data/test/radiator/operation_test.rb +117 -0
- data/test/radiator/ssc/blockchain_test.rb +58 -0
- data/test/radiator/ssc/contracts_test.rb +65 -0
- data/test/radiator/stream_test.rb +48 -0
- data/test/radiator/tag_api_test.rb +40 -0
- data/test/radiator/transaction_test.rb +755 -0
- data/test/test_helper.rb +66 -0
- metadata +190 -80
- data/.codeclimate.yml +0 -19
- data/.gitignore +0 -52
- data/.travis.yml +0 -23
- data/gource.sh +0 -8
- data/images/Anthony Martin.png +0 -0
- data/images/Marvin Hofmann.jpg +0 -0
- data/images/Marvin Hofmann.png +0 -0
- data/lib/steem.rb +0 -17
@@ -0,0 +1,92 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.steem-engine.com/rpc/blockchain
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"method":"getBlockInfo","params":{"blockNumber":-1},"jsonrpc":"2.0","id":2}'
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- radiator/0.4.8.pre.1
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
Connection:
|
19
|
+
- keep-alive
|
20
|
+
Keep-Alive:
|
21
|
+
- '30'
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 200
|
25
|
+
message: OK
|
26
|
+
headers:
|
27
|
+
Server:
|
28
|
+
- nginx/1.10.3 (Ubuntu)
|
29
|
+
Date:
|
30
|
+
- Sat, 17 Oct 2020 04:07:40 GMT
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
Content-Length:
|
34
|
+
- '38'
|
35
|
+
Connection:
|
36
|
+
- keep-alive
|
37
|
+
X-Powered-By:
|
38
|
+
- Express
|
39
|
+
Access-Control-Allow-Origin:
|
40
|
+
- "*"
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: '{"jsonrpc":"2.0","id":2,"result":null}'
|
44
|
+
http_version:
|
45
|
+
recorded_at: Sat, 17 Oct 2020 04:07:40 GMT
|
46
|
+
- request:
|
47
|
+
method: post
|
48
|
+
uri: https://api.steem-engine.com/rpc/blockchain
|
49
|
+
body:
|
50
|
+
encoding: UTF-8
|
51
|
+
string: '{"method":"getBlockInfo","params":{"blockNumber":1},"jsonrpc":"2.0","id":1}'
|
52
|
+
headers:
|
53
|
+
Content-Type:
|
54
|
+
- application/json
|
55
|
+
User-Agent:
|
56
|
+
- radiator/0.4.8.pre.1
|
57
|
+
Accept-Encoding:
|
58
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
59
|
+
Accept:
|
60
|
+
- "*/*"
|
61
|
+
Connection:
|
62
|
+
- keep-alive
|
63
|
+
Keep-Alive:
|
64
|
+
- '30'
|
65
|
+
response:
|
66
|
+
status:
|
67
|
+
code: 200
|
68
|
+
message: OK
|
69
|
+
headers:
|
70
|
+
Server:
|
71
|
+
- nginx/1.10.3 (Ubuntu)
|
72
|
+
Date:
|
73
|
+
- Sat, 17 Oct 2020 04:07:40 GMT
|
74
|
+
Content-Type:
|
75
|
+
- application/json; charset=utf-8
|
76
|
+
Transfer-Encoding:
|
77
|
+
- chunked
|
78
|
+
Connection:
|
79
|
+
- keep-alive
|
80
|
+
Vary:
|
81
|
+
- Accept-Encoding
|
82
|
+
X-Powered-By:
|
83
|
+
- Express
|
84
|
+
Access-Control-Allow-Origin:
|
85
|
+
- "*"
|
86
|
+
body:
|
87
|
+
encoding: ASCII-8BIT
|
88
|
+
string: '{"jsonrpc":"2.0","id":1,"result":{"_id":1,"blockNumber":1,"refSteemBlockNumber":29866321,"refSteemBlockId":"01c7b951771a28e904c55940dde3dd014e075884","prevRefSteemBlockId":"01c7b95075caed4c2276010d87a555105f720b82","previousHash":"c1dee96a6b7a0cc9408ccb407ab641f444c26f6859ba33b9c9ba2c0a368d20b2","previousDatabaseHash":"a3daa72622eb02abd0b1614943f45500633dc10789477e8ee538a8398e61f976","timestamp":"2019-01-29T01:18:03","transactions":[{"refSteemBlockNumber":29866321,"transactionId":"df846ffdbd87f3fae2a60993dae9d16d44c814e3","sender":"yabapmatt","contract":"sscstore","action":"buy","payload":"{\"recipient\":\"steemsc\",\"amountSTEEMSBD\":\"100.000
|
89
|
+
STEEM\",\"isSignedWithActiveKey\":true}","executedCodeHash":"2189984c5648194eb352aad01bb5b8235367a4c040c42b7d5bac107270e94c49986d043b17a3da825157d3edaec1f23d2cecb2637a1f1bbbdb4c66caa958797a","hash":"07bf1380f6339aa692009028376b3ca685f8b7d9a5a73893bf599f8612c99c2b","databaseHash":"bb464a0df58fa01162120bd37e64157495188d070ee4710d71488e9381a4156b","logs":"{\"events\":[{\"contract\":\"tokens\",\"event\":\"transfer\",\"data\":{\"from\":\"steemsc\",\"to\":\"yabapmatt\",\"symbol\":\"ENG\",\"quantity\":100}}]}"}],"virtualTransactions":[],"hash":"9268b81c5b1503c7a0d87011030d3e25f630648a085fd349279e72b29a653ff3","databaseHash":"fd6f6fecea389797046dad441498d220498741b3ff23e91fde73d8c183bf232b","merkleRoot":"776a70789b83aed023eee0c7e77c29da43f97e226cbedf16bbb22664a13ad5d2","signature":"1f3f15e7b97d768e37ffffa8e8666db1302e77cc98415534e5f259b263f3db30c64147bfa18e0b5ffb23badd3d4a07b6c4fb2324d20591c3d581fea4c9c18a18b4"}}'
|
90
|
+
http_version:
|
91
|
+
recorded_at: Sat, 17 Oct 2020 04:07:40 GMT
|
92
|
+
recorded_with: VCR 5.0.0
|
@@ -0,0 +1,90 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.steem-engine.com/rpc/blockchain
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"method":"getBlockInfo","params":{"blockNumber":-1},"jsonrpc":"2.0","id":2}'
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- radiator/0.4.8.pre.1
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
Connection:
|
19
|
+
- keep-alive
|
20
|
+
Keep-Alive:
|
21
|
+
- '30'
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 200
|
25
|
+
message: OK
|
26
|
+
headers:
|
27
|
+
Server:
|
28
|
+
- nginx/1.10.3 (Ubuntu)
|
29
|
+
Date:
|
30
|
+
- Sat, 17 Oct 2020 04:07:44 GMT
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
Content-Length:
|
34
|
+
- '38'
|
35
|
+
Connection:
|
36
|
+
- keep-alive
|
37
|
+
X-Powered-By:
|
38
|
+
- Express
|
39
|
+
Access-Control-Allow-Origin:
|
40
|
+
- "*"
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: '{"jsonrpc":"2.0","id":2,"result":null}'
|
44
|
+
http_version:
|
45
|
+
recorded_at: Sat, 17 Oct 2020 04:07:44 GMT
|
46
|
+
- request:
|
47
|
+
method: post
|
48
|
+
uri: https://api.steem-engine.com/rpc/blockchain
|
49
|
+
body:
|
50
|
+
encoding: UTF-8
|
51
|
+
string: '{"method":"getBlockInfo","params":{"blockNumber":"WRONG"},"jsonrpc":"2.0","id":1}'
|
52
|
+
headers:
|
53
|
+
Content-Type:
|
54
|
+
- application/json
|
55
|
+
User-Agent:
|
56
|
+
- radiator/0.4.8.pre.1
|
57
|
+
Accept-Encoding:
|
58
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
59
|
+
Accept:
|
60
|
+
- "*/*"
|
61
|
+
Connection:
|
62
|
+
- keep-alive
|
63
|
+
Keep-Alive:
|
64
|
+
- '30'
|
65
|
+
response:
|
66
|
+
status:
|
67
|
+
code: 200
|
68
|
+
message: OK
|
69
|
+
headers:
|
70
|
+
Server:
|
71
|
+
- nginx/1.10.3 (Ubuntu)
|
72
|
+
Date:
|
73
|
+
- Sat, 17 Oct 2020 04:07:44 GMT
|
74
|
+
Content-Type:
|
75
|
+
- application/json; charset=utf-8
|
76
|
+
Content-Length:
|
77
|
+
- '110'
|
78
|
+
Connection:
|
79
|
+
- keep-alive
|
80
|
+
X-Powered-By:
|
81
|
+
- Express
|
82
|
+
Access-Control-Allow-Origin:
|
83
|
+
- "*"
|
84
|
+
body:
|
85
|
+
encoding: UTF-8
|
86
|
+
string: '{"jsonrpc":"2.0","id":1,"error":{"code":400,"message":"missing or wrong
|
87
|
+
parameters: blockNumber is required"}}'
|
88
|
+
http_version:
|
89
|
+
recorded_at: Sat, 17 Oct 2020 04:07:45 GMT
|
90
|
+
recorded_with: VCR 5.0.0
|
@@ -0,0 +1,91 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.steem-engine.com/rpc/blockchain
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"method":"getBlockInfo","params":{"blockNumber":-1},"jsonrpc":"2.0","id":2}'
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- radiator/0.4.8.pre.1
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
Connection:
|
19
|
+
- keep-alive
|
20
|
+
Keep-Alive:
|
21
|
+
- '30'
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 200
|
25
|
+
message: OK
|
26
|
+
headers:
|
27
|
+
Server:
|
28
|
+
- nginx/1.10.3 (Ubuntu)
|
29
|
+
Date:
|
30
|
+
- Sat, 17 Oct 2020 04:07:42 GMT
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
Content-Length:
|
34
|
+
- '38'
|
35
|
+
Connection:
|
36
|
+
- keep-alive
|
37
|
+
X-Powered-By:
|
38
|
+
- Express
|
39
|
+
Access-Control-Allow-Origin:
|
40
|
+
- "*"
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: '{"jsonrpc":"2.0","id":2,"result":null}'
|
44
|
+
http_version:
|
45
|
+
recorded_at: Sat, 17 Oct 2020 04:07:42 GMT
|
46
|
+
- request:
|
47
|
+
method: post
|
48
|
+
uri: https://api.steem-engine.com/rpc/blockchain
|
49
|
+
body:
|
50
|
+
encoding: UTF-8
|
51
|
+
string: '{"method":"getLatestBlockInfo","jsonrpc":"2.0","id":1}'
|
52
|
+
headers:
|
53
|
+
Content-Type:
|
54
|
+
- application/json
|
55
|
+
User-Agent:
|
56
|
+
- radiator/0.4.8.pre.1
|
57
|
+
Accept-Encoding:
|
58
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
59
|
+
Accept:
|
60
|
+
- "*/*"
|
61
|
+
Connection:
|
62
|
+
- keep-alive
|
63
|
+
Keep-Alive:
|
64
|
+
- '30'
|
65
|
+
response:
|
66
|
+
status:
|
67
|
+
code: 200
|
68
|
+
message: OK
|
69
|
+
headers:
|
70
|
+
Server:
|
71
|
+
- nginx/1.10.3 (Ubuntu)
|
72
|
+
Date:
|
73
|
+
- Sat, 17 Oct 2020 04:07:42 GMT
|
74
|
+
Content-Type:
|
75
|
+
- application/json; charset=utf-8
|
76
|
+
Transfer-Encoding:
|
77
|
+
- chunked
|
78
|
+
Connection:
|
79
|
+
- keep-alive
|
80
|
+
Vary:
|
81
|
+
- Accept-Encoding
|
82
|
+
X-Powered-By:
|
83
|
+
- Express
|
84
|
+
Access-Control-Allow-Origin:
|
85
|
+
- "*"
|
86
|
+
body:
|
87
|
+
encoding: ASCII-8BIT
|
88
|
+
string: '{"jsonrpc":"2.0","id":1,"result":{"_id":8026333,"blockNumber":8026333,"refSteemBlockNumber":47791878,"refSteemBlockId":"02d93f06077b3ce47cab0c9f3802a6e82eef2a57","prevRefSteemBlockId":"02d93f05e9f57b8caf4d30e40146d0ebcd1cf462","previousHash":"70bc589d54704b9938094904cb0880fcd4ec8c1396de805d87678bfc5705c85b","previousDatabaseHash":"a7d8e52d98382ff15bad6983a2002842eea88b436a6e09bf0eed8fbcfc4321b7","timestamp":"2020-10-17T04:07:18","transactions":[{"refSteemBlockNumber":47791878,"transactionId":"fe5f86a9ccc6f540d2a0883ab992618376198e79","sender":"sklara","contract":"tokens","action":"stake","payload":"{\"symbol\":\"DBLOG\",\"to\":\"sklara\",\"quantity\":\"1231.283\",\"isSignedWithActiveKey\":true}","executedCodeHash":"d3ab1afa743f5322eb1b5da7ada99c43f7d26f47cfaab98acb9322c929b23ea6","hash":"4e99a0fb6a7ecbdc95c3f2add26b6f04ac4f77cdcf88372cd0111db42698d0ac","databaseHash":"951d64b5f2161858a74fdb754ae4a062bf1f590037552ca5389b8822b51eaacf","logs":"{\"events\":[{\"contract\":\"tokens\",\"event\":\"stake\",\"data\":{\"account\":\"sklara\",\"symbol\":\"DBLOG\",\"quantity\":\"1231.283\"}}]}"}],"virtualTransactions":[],"hash":"8d7f85158e09e716bbd81fcf5222771d5886f440f366ff5a5b6abe7b50a55b31","databaseHash":"95349cb152f5a05cadb7e76ddcdc02ea50b8da8ed06409ffa2f6f752f2da141c","merkleRoot":"759645a12eff87180a4bf6c80487003a890df9ade69ef5bd897001b8f865b733","round":null,"roundHash":"","witness":"","signingKey":"","roundSignature":""}}'
|
89
|
+
http_version:
|
90
|
+
recorded_at: Sat, 17 Oct 2020 04:07:42 GMT
|
91
|
+
recorded_with: VCR 5.0.0
|
@@ -0,0 +1,92 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.steem-engine.com/rpc/blockchain
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"method":"getBlockInfo","params":{"blockNumber":-1},"jsonrpc":"2.0","id":2}'
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- radiator/0.4.8.pre.1
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
Connection:
|
19
|
+
- keep-alive
|
20
|
+
Keep-Alive:
|
21
|
+
- '30'
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 200
|
25
|
+
message: OK
|
26
|
+
headers:
|
27
|
+
Server:
|
28
|
+
- nginx/1.10.3 (Ubuntu)
|
29
|
+
Date:
|
30
|
+
- Sat, 17 Oct 2020 04:07:46 GMT
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
Content-Length:
|
34
|
+
- '38'
|
35
|
+
Connection:
|
36
|
+
- keep-alive
|
37
|
+
X-Powered-By:
|
38
|
+
- Express
|
39
|
+
Access-Control-Allow-Origin:
|
40
|
+
- "*"
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: '{"jsonrpc":"2.0","id":2,"result":null}'
|
44
|
+
http_version:
|
45
|
+
recorded_at: Sat, 17 Oct 2020 04:07:46 GMT
|
46
|
+
- request:
|
47
|
+
method: post
|
48
|
+
uri: https://api.steem-engine.com/rpc/blockchain
|
49
|
+
body:
|
50
|
+
encoding: UTF-8
|
51
|
+
string: '{"method":"getTransactionInfo","params":{"txid":"df846ffdbd87f3fae2a60993dae9d16d44c814e3"},"jsonrpc":"2.0","id":1}'
|
52
|
+
headers:
|
53
|
+
Content-Type:
|
54
|
+
- application/json
|
55
|
+
User-Agent:
|
56
|
+
- radiator/0.4.8.pre.1
|
57
|
+
Accept-Encoding:
|
58
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
59
|
+
Accept:
|
60
|
+
- "*/*"
|
61
|
+
Connection:
|
62
|
+
- keep-alive
|
63
|
+
Keep-Alive:
|
64
|
+
- '30'
|
65
|
+
response:
|
66
|
+
status:
|
67
|
+
code: 200
|
68
|
+
message: OK
|
69
|
+
headers:
|
70
|
+
Server:
|
71
|
+
- nginx/1.10.3 (Ubuntu)
|
72
|
+
Date:
|
73
|
+
- Sat, 17 Oct 2020 04:07:46 GMT
|
74
|
+
Content-Type:
|
75
|
+
- application/json; charset=utf-8
|
76
|
+
Transfer-Encoding:
|
77
|
+
- chunked
|
78
|
+
Connection:
|
79
|
+
- keep-alive
|
80
|
+
Vary:
|
81
|
+
- Accept-Encoding
|
82
|
+
X-Powered-By:
|
83
|
+
- Express
|
84
|
+
Access-Control-Allow-Origin:
|
85
|
+
- "*"
|
86
|
+
body:
|
87
|
+
encoding: ASCII-8BIT
|
88
|
+
string: '{"jsonrpc":"2.0","id":1,"result":{"blockNumber":1,"refSteemBlockNumber":29866321,"transactionId":"df846ffdbd87f3fae2a60993dae9d16d44c814e3","sender":"yabapmatt","contract":"sscstore","action":"buy","payload":"{\"recipient\":\"steemsc\",\"amountSTEEMSBD\":\"100.000
|
89
|
+
STEEM\",\"isSignedWithActiveKey\":true}","executedCodeHash":"2189984c5648194eb352aad01bb5b8235367a4c040c42b7d5bac107270e94c49986d043b17a3da825157d3edaec1f23d2cecb2637a1f1bbbdb4c66caa958797a","hash":"07bf1380f6339aa692009028376b3ca685f8b7d9a5a73893bf599f8612c99c2b","databaseHash":"bb464a0df58fa01162120bd37e64157495188d070ee4710d71488e9381a4156b","logs":"{\"events\":[{\"contract\":\"tokens\",\"event\":\"transfer\",\"data\":{\"from\":\"steemsc\",\"to\":\"yabapmatt\",\"symbol\":\"ENG\",\"quantity\":100}}]}"}}'
|
90
|
+
http_version:
|
91
|
+
recorded_at: Sat, 17 Oct 2020 04:07:46 GMT
|
92
|
+
recorded_with: VCR 5.0.0
|
@@ -0,0 +1,366 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.steem-engine.com/rpc/contracts
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"method":"find","params":{"contract":"tokens","table":"transfers","query":{"symbol":""},"limit":0},"jsonrpc":"2.0","id":2}'
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- radiator/0.4.8.pre.1
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
Connection:
|
19
|
+
- keep-alive
|
20
|
+
Keep-Alive:
|
21
|
+
- '30'
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 200
|
25
|
+
message: OK
|
26
|
+
headers:
|
27
|
+
Server:
|
28
|
+
- nginx/1.10.3 (Ubuntu)
|
29
|
+
Date:
|
30
|
+
- Sat, 17 Oct 2020 04:07:49 GMT
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
Content-Length:
|
34
|
+
- '38'
|
35
|
+
Connection:
|
36
|
+
- keep-alive
|
37
|
+
X-Powered-By:
|
38
|
+
- Express
|
39
|
+
Access-Control-Allow-Origin:
|
40
|
+
- "*"
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: '{"jsonrpc":"2.0","id":2,"result":null}'
|
44
|
+
http_version:
|
45
|
+
recorded_at: Sat, 17 Oct 2020 04:07:50 GMT
|
46
|
+
- request:
|
47
|
+
method: post
|
48
|
+
uri: https://api.steem-engine.com/rpc/contracts
|
49
|
+
body:
|
50
|
+
encoding: UTF-8
|
51
|
+
string: '{"method":"getContract","params":{"name":"tokens"},"jsonrpc":"2.0","id":1}'
|
52
|
+
headers:
|
53
|
+
Content-Type:
|
54
|
+
- application/json
|
55
|
+
User-Agent:
|
56
|
+
- radiator/0.4.8.pre.1
|
57
|
+
Accept-Encoding:
|
58
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
59
|
+
Accept:
|
60
|
+
- "*/*"
|
61
|
+
Connection:
|
62
|
+
- keep-alive
|
63
|
+
Keep-Alive:
|
64
|
+
- '30'
|
65
|
+
response:
|
66
|
+
status:
|
67
|
+
code: 200
|
68
|
+
message: OK
|
69
|
+
headers:
|
70
|
+
Server:
|
71
|
+
- nginx/1.10.3 (Ubuntu)
|
72
|
+
Date:
|
73
|
+
- Sat, 17 Oct 2020 04:07:50 GMT
|
74
|
+
Content-Type:
|
75
|
+
- application/json; charset=utf-8
|
76
|
+
Transfer-Encoding:
|
77
|
+
- chunked
|
78
|
+
Connection:
|
79
|
+
- keep-alive
|
80
|
+
Vary:
|
81
|
+
- Accept-Encoding
|
82
|
+
X-Powered-By:
|
83
|
+
- Express
|
84
|
+
Access-Control-Allow-Origin:
|
85
|
+
- "*"
|
86
|
+
body:
|
87
|
+
encoding: ASCII-8BIT
|
88
|
+
string: '{"jsonrpc":"2.0","id":1,"result":{"_id":"tokens","owner":"steemsc","code":"\n function
|
89
|
+
wrapper () {\n RegExp.prototype.constructor = function () { };\n RegExp.prototype.exec
|
90
|
+
= function () { };\n RegExp.prototype.test = function () { };\n \n let
|
91
|
+
actions = {};\n \n const ACCOUNT_BLACKLIST={gateiodeposit:1,deepcrypto8:1,bittrex:1,poloniex:1,\"huobi-pro\":1,\"honey-swap\":1,\"binance-hot\":1,bitvavo:1,blocktrades:1,probitsteem:1,probithive:1,ionomy:1};actions.createSSC=async()=>{let
|
92
|
+
tableExists=await api.db.tableExists(\"tokens\");if(!1===tableExists){await
|
93
|
+
api.db.createTable(\"tokens\",[\"symbol\"]),await api.db.createTable(\"balances\",[\"account\"]),await
|
94
|
+
api.db.createTable(\"contractsBalances\",[\"account\"]),await api.db.createTable(\"params\");const
|
95
|
+
params={tokenCreationFee:\"0\"};await api.db.insert(\"params\",params)}else{const
|
96
|
+
params=await api.db.findOne(\"params\",{});params.enableDelegationFee=\"1000\",params.enableStakingFee=\"1000\",await
|
97
|
+
api.db.update(\"params\",params)}tableExists=await api.db.tableExists(\"pendingUnstakes\"),!1===tableExists&&await
|
98
|
+
api.db.createTable(\"pendingUnstakes\",[\"account\",\"unstakeCompleteTimestamp\"]),tableExists=await
|
99
|
+
api.db.tableExists(\"delegations\"),!1===tableExists&&(await api.db.createTable(\"delegations\",[\"from\",\"to\"]),await
|
100
|
+
api.db.createTable(\"pendingUndelegations\",[\"account\",\"completeTimestamp\"]));let
|
101
|
+
token=await api.db.findOne(\"tokens\",{symbol:\"STEEMP\"});token&&token.precision<8&&(token.precision=8,await
|
102
|
+
api.db.update(\"tokens\",token)),token=await api.db.findOne(\"tokens\",{symbol:\"ENG\"}),void
|
103
|
+
0!==token.stakingEnabled&&!1!==token.stakingEnabled||(token.stakingEnabled=!0,token.totalStaked=\"0\",token.unstakingCooldown=40,token.numberTransactions=4,token.delegationEnabled=!0,token.undelegationCooldown=7,await
|
104
|
+
api.db.update(\"tokens\",token))};const balanceTemplate={account:null,symbol:null,balance:\"0\",stake:\"0\",pendingUnstake:\"0\",delegationsIn:\"0\",delegationsOut:\"0\",pendingUndelegations:\"0\"},calculateBalance=(balance,quantity,precision,add)=>add?api.BigNumber(balance).plus(quantity).toFixed(precision):api.BigNumber(balance).minus(quantity).toFixed(precision),countDecimals=value=>api.BigNumber(value).dp(),addStake=async(account,token,quantity)=>{let
|
105
|
+
balance=await api.db.findOne(\"balances\",{account:account,symbol:token.symbol});null===balance&&(balance=balanceTemplate,balance.account=account,balance.symbol=token.symbol,balance=await
|
106
|
+
api.db.insert(\"balances\",balance)),void 0===balance.stake&&(balance.stake=\"0\",balance.pendingUnstake=\"0\");const
|
107
|
+
originalStake=balance.stake;return balance.stake=calculateBalance(balance.stake,quantity,token.precision,!0),!!api.assert(api.BigNumber(balance.stake).gt(originalStake),\"cannot
|
108
|
+
add\")&&(await api.db.update(\"balances\",balance),void 0===token.totalStaked&&(token.totalStaked=\"0\"),token.totalStaked=calculateBalance(token.totalStaked,quantity,token.precision,!0),await
|
109
|
+
api.db.update(\"tokens\",token),!0)},subStake=async(account,token,quantity)=>{const
|
110
|
+
balance=await api.db.findOne(\"balances\",{account:account,symbol:token.symbol});if(api.assert(null!==balance,\"balance
|
111
|
+
does not exist\")&&api.assert(api.BigNumber(balance.stake).gte(quantity),\"overdrawn
|
112
|
+
stake\")){const originalStake=balance.stake,originalPendingStake=balance.pendingUnstake;if(balance.stake=calculateBalance(balance.stake,quantity,token.precision,!1),balance.pendingUnstake=calculateBalance(balance.pendingUnstake,quantity,token.precision,!0),api.assert(api.BigNumber(balance.stake).lt(originalStake)&&api.BigNumber(balance.pendingUnstake).gt(originalPendingStake),\"cannot
|
113
|
+
subtract\"))return await api.db.update(\"balances\",balance),!0}return!1},subBalance=async(account,token,quantity,table)=>{const
|
114
|
+
balance=await api.db.findOne(table,{account:account,symbol:token.symbol});if(api.assert(null!==balance,\"balance
|
115
|
+
does not exist\")&&api.assert(api.BigNumber(balance.balance).gte(quantity),\"overdrawn
|
116
|
+
balance\")){const originalBalance=balance.balance;if(balance.balance=calculateBalance(balance.balance,quantity,token.precision,!1),api.assert(api.BigNumber(balance.balance).lt(originalBalance),\"cannot
|
117
|
+
subtract\"))return await api.db.update(table,balance),!0}return!1},addBalance=async(account,token,quantity,table)=>{let
|
118
|
+
balance=await api.db.findOne(table,{account:account,symbol:token.symbol});if(null===balance)return
|
119
|
+
balance=balanceTemplate,balance.account=account,balance.symbol=token.symbol,balance.balance=quantity,await
|
120
|
+
api.db.insert(table,balance),!0;const originalBalance=balance.balance;return
|
121
|
+
balance.balance=calculateBalance(balance.balance,quantity,token.precision,!0),!!api.assert(api.BigNumber(balance.balance).gt(originalBalance),\"cannot
|
122
|
+
add\")&&(await api.db.update(table,balance),!0)};actions.updateParams=async
|
123
|
+
payload=>{if(api.sender!==api.owner)return;const{tokenCreationFee:tokenCreationFee}=payload,params=await
|
124
|
+
api.db.findOne(\"params\",{});params.tokenCreationFee=tokenCreationFee,await
|
125
|
+
api.db.update(\"params\",params)},actions.updateUrl=async payload=>{const{url:url,symbol:symbol}=payload;if(api.assert(symbol&&\"string\"==typeof
|
126
|
+
symbol&&url&&\"string\"==typeof url,\"invalid params\")&&api.assert(url.length<=255,\"invalid
|
127
|
+
url: max length of 255\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(token&&api.assert(token.issuer===api.sender,\"must
|
128
|
+
be the issuer\"))try{const metadata=JSON.parse(token.metadata);api.assert(metadata&&metadata.url,\"an
|
129
|
+
error occured when trying to update the url\")&&(metadata.url=url,token.metadata=JSON.stringify(metadata),await
|
130
|
+
api.db.update(\"tokens\",token))}catch(e){}}},actions.updateMetadata=async
|
131
|
+
payload=>{const{metadata:metadata,symbol:symbol}=payload;if(api.assert(symbol&&\"string\"==typeof
|
132
|
+
symbol&&metadata&&\"object\"==typeof metadata,\"invalid params\")){const token=await
|
133
|
+
api.db.findOne(\"tokens\",{symbol:symbol});if(token&&api.assert(token.issuer===api.sender,\"must
|
134
|
+
be the issuer\"))try{const finalMetadata=JSON.stringify(metadata);api.assert(finalMetadata.length<=1e3,\"invalid
|
135
|
+
metadata: max length of 1000\")&&(token.metadata=finalMetadata,await api.db.update(\"tokens\",token))}catch(e){}}},actions.updatePrecision=async
|
136
|
+
payload=>{const{symbol:symbol,precision:precision,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
137
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
138
|
+
symbol)&&api.assert(precision>0&&precision<=8&&Number.isInteger(precision),\"invalid
|
139
|
+
precision\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});token&&api.assert(token.issuer===api.sender,\"must
|
140
|
+
be the issuer\")&&api.assert(precision>token.precision,\"precision can only
|
141
|
+
be increased\")&&(token.precision=precision,await api.db.update(\"tokens\",token))}},actions.transferOwnership=async
|
142
|
+
payload=>{const{symbol:symbol,to:to,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
143
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
144
|
+
symbol&&to&&\"string\"==typeof to,\"invalid params\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(token&&api.assert(token.issuer===api.sender,\"must
|
145
|
+
be the issuer\")){const finalTo=to.trim();api.assert(api.isValidAccountName(finalTo),\"invalid
|
146
|
+
to\")&&(token.issuer=finalTo,await api.db.update(\"tokens\",token))}}},actions.create=async
|
147
|
+
payload=>{const{name:name,symbol:symbol,url:url,precision:precision,maxSupply:maxSupply,isSignedWithActiveKey:isSignedWithActiveKey}=payload,params=await
|
148
|
+
api.db.findOne(\"params\",{}),{tokenCreationFee:tokenCreationFee}=params,utilityTokenBalance=await
|
149
|
+
api.db.findOne(\"balances\",{account:api.sender,symbol:\"ENG\"}),authorizedCreation=!!api.BigNumber(tokenCreationFee).lte(0)||utilityTokenBalance&&api.BigNumber(utilityTokenBalance.balance).gte(tokenCreationFee);if(api.assert(authorizedCreation,\"you
|
150
|
+
must have enough tokens to cover the creation fees\")&&api.assert(!0===isSignedWithActiveKey,\"you
|
151
|
+
must use a custom_json signed with your active key\")&&api.assert(name&&\"string\"==typeof
|
152
|
+
name&&symbol&&\"string\"==typeof symbol&&(void 0===url||url&&\"string\"==typeof
|
153
|
+
url)&&(precision&&\"number\"==typeof precision||0===precision)&&maxSupply&&\"string\"==typeof
|
154
|
+
maxSupply&&!api.BigNumber(maxSupply).isNaN(),\"invalid params\")&&api.assert(api.validator.isAlpha(symbol)&&api.validator.isUppercase(symbol)&&symbol.length>0&&symbol.length<=10,\"invalid
|
155
|
+
symbol: uppercase letters only, max length of 10\")&&api.assert(api.validator.isAlphanumeric(api.validator.blacklist(name,\"
|
156
|
+
\"))&&name.length>0&&name.length<=50,\"invalid name: letters, numbers, whitespaces
|
157
|
+
only, max length of 50\")&&api.assert(void 0===url||url.length<=255,\"invalid
|
158
|
+
url: max length of 255\")&&api.assert(precision>=0&&precision<=8&&Number.isInteger(precision),\"invalid
|
159
|
+
precision\")&&api.assert(api.BigNumber(maxSupply).gt(0),\"maxSupply must be
|
160
|
+
positive\")&&api.assert(api.BigNumber(maxSupply).lte(Number.MAX_SAFE_INTEGER),\"maxSupply
|
161
|
+
must be lower than \"+Number.MAX_SAFE_INTEGER)){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null===token,\"symbol
|
162
|
+
already exists\")){let metadata={url:void 0===url?\"\":url};metadata=JSON.stringify(metadata);const
|
163
|
+
newToken={issuer:api.sender,symbol:symbol,name:name,metadata:metadata,precision:precision,maxSupply:api.BigNumber(maxSupply).toFixed(precision),supply:\"0\",circulatingSupply:\"0\",stakingEnabled:!1,unstakingCooldown:1,delegationEnabled:!1,undelegationCooldown:0};await
|
164
|
+
api.db.insert(\"tokens\",newToken),api.BigNumber(tokenCreationFee).gt(0)&&await
|
165
|
+
actions.transfer({to:\"null\",symbol:\"ENG\",quantity:tokenCreationFee,isSignedWithActiveKey:isSignedWithActiveKey})}}},actions.issue=async
|
166
|
+
payload=>{const{to:to,symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
167
|
+
must use a custom_json signed with your active key\")&&api.assert(to&&\"string\"==typeof
|
168
|
+
to&&symbol&&\"string\"==typeof symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
169
|
+
params\")){const finalTo=to.trim(),token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
170
|
+
does not exist\")&&api.assert(token.issuer===api.sender,\"not allowed to issue
|
171
|
+
tokens\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol precision
|
172
|
+
mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must issue positive
|
173
|
+
quantity\")&&api.assert(api.BigNumber(token.maxSupply).minus(token.supply).gte(quantity),\"quantity
|
174
|
+
exceeds available supply\")&&api.assert(api.isValidAccountName(finalTo),\"invalid
|
175
|
+
to\")){let res=await addBalance(token.issuer,token,quantity,\"balances\");!0===res&&finalTo!==token.issuer&&await
|
176
|
+
subBalance(token.issuer,token,quantity,\"balances\")&&(res=await addBalance(finalTo,token,quantity,\"balances\"),!1===res&&await
|
177
|
+
addBalance(token.issuer,token,quantity,\"balances\")),!0===res&&(token.supply=calculateBalance(token.supply,quantity,token.precision,!0),\"null\"!==finalTo&&(token.circulatingSupply=calculateBalance(token.circulatingSupply,quantity,token.precision,!0)),await
|
178
|
+
api.db.update(\"tokens\",token),api.emit(\"transferFromContract\",{from:\"tokens\",to:finalTo,symbol:symbol,quantity:quantity}))}}},actions.issueToContract=async
|
179
|
+
payload=>{const{to:to,symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
180
|
+
must use a custom_json signed with your active key\")&&api.assert(to&&\"string\"==typeof
|
181
|
+
to&&symbol&&\"string\"==typeof symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
182
|
+
params\")){const finalTo=to.trim(),token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
183
|
+
does not exist\")&&api.assert(token.issuer===api.sender,\"not allowed to issue
|
184
|
+
tokens\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol precision
|
185
|
+
mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must issue positive
|
186
|
+
quantity\")&&api.assert(api.BigNumber(token.maxSupply).minus(token.supply).gte(quantity),\"quantity
|
187
|
+
exceeds available supply\")&&api.assert(finalTo.length>=3&&finalTo.length<=50,\"invalid
|
188
|
+
to\")){!0===await addBalance(finalTo,token,quantity,\"contractsBalances\")&&(token.supply=calculateBalance(token.supply,quantity,token.precision,!0),\"null\"!==finalTo&&(token.circulatingSupply=calculateBalance(token.circulatingSupply,quantity,token.precision,!0)),await
|
189
|
+
api.db.update(\"tokens\",token),api.emit(\"issueToContract\",{from:\"tokens\",to:finalTo,symbol:symbol,quantity:quantity}))}}},actions.transfer=async
|
190
|
+
payload=>{const{to:to,symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
191
|
+
must use a custom_json signed with your active key\")&&api.assert(to&&\"string\"==typeof
|
192
|
+
to&&symbol&&\"string\"==typeof symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
193
|
+
params\")){const finalTo=to.trim();if(api.assert(finalTo!==api.sender,\"cannot
|
194
|
+
transfer to self\")&&api.assert(api.isValidAccountName(finalTo),\"invalid
|
195
|
+
to\")&&api.assert(void 0===ACCOUNT_BLACKLIST[finalTo],\"not allowed to send
|
196
|
+
to \"+finalTo)){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
197
|
+
does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
198
|
+
precision mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must transfer
|
199
|
+
positive quantity\")&&await subBalance(api.sender,token,quantity,\"balances\")){return!1===await
|
200
|
+
addBalance(finalTo,token,quantity,\"balances\")?(await addBalance(api.sender,token,quantity,\"balances\"),!1):(\"null\"===finalTo&&(token.circulatingSupply=calculateBalance(token.circulatingSupply,quantity,token.precision,!1),await
|
201
|
+
api.db.update(\"tokens\",token)),api.emit(\"transfer\",{from:api.sender,to:finalTo,symbol:symbol,quantity:quantity}),!0)}}}return!1},actions.transferToContract=async
|
202
|
+
payload=>{const{from:from,to:to,symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload,finalFrom=void
|
203
|
+
0===from||\"null\"!==api.sender?api.sender:from;if(api.assert(!0===isSignedWithActiveKey||\"null\"===api.sender,\"you
|
204
|
+
must use a custom_json signed with your active key\")&&api.assert(to&&\"string\"==typeof
|
205
|
+
to&&symbol&&\"string\"==typeof symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
206
|
+
params\")){const finalTo=to.trim().toLowerCase();if(api.assert(finalTo!==finalFrom,\"cannot
|
207
|
+
transfer to self\")&&api.assert(finalTo.length>=3&&finalTo.length<=50,\"invalid
|
208
|
+
to\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
209
|
+
does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
210
|
+
precision mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must transfer
|
211
|
+
positive quantity\")&&await subBalance(finalFrom,token,quantity,\"balances\")){!1===await
|
212
|
+
addBalance(finalTo,token,quantity,\"contractsBalances\")?await addBalance(finalFrom,token,quantity,\"balances\"):(\"null\"===finalTo&&(token.circulatingSupply=calculateBalance(token.circulatingSupply,quantity,token.precision,!1),await
|
213
|
+
api.db.update(\"tokens\",token)),api.emit(\"transferToContract\",{from:finalFrom,to:finalTo,symbol:symbol,quantity:quantity}))}}}},actions.transferFromContract=async
|
214
|
+
payload=>{if(api.assert(\"null\"===api.sender,\"not authorized\")){const{from:from,to:to,symbol:symbol,quantity:quantity,type:type}=payload,types=[\"user\",\"contract\"];if(api.assert(to&&\"string\"==typeof
|
215
|
+
to&&from&&\"string\"==typeof from&&symbol&&\"string\"==typeof symbol&&type&&types.includes(type)&&quantity&&\"string\"==typeof
|
216
|
+
quantity&&!api.BigNumber(quantity).isNaN(),\"invalid params\")){const finalTo=to.trim(),table=\"user\"===type?\"balances\":\"contractsBalances\";if(api.assert(\"user\"===type||\"contract\"===type&&finalTo!==from,\"cannot
|
217
|
+
transfer to self\")){const toValid=\"user\"===type?api.isValidAccountName(finalTo):finalTo.length>=3&&finalTo.length<=50;if(api.assert(!0===toValid,\"invalid
|
218
|
+
to\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
219
|
+
does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
220
|
+
precision mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must transfer
|
221
|
+
positive quantity\")&&await subBalance(from,token,quantity,\"contractsBalances\")){!1===await
|
222
|
+
addBalance(finalTo,token,quantity,table)?await addBalance(from,token,quantity,\"contractsBalances\"):(\"null\"===finalTo&&(token.circulatingSupply=calculateBalance(token.circulatingSupply,quantity,token.precision,!1),await
|
223
|
+
api.db.update(\"tokens\",token)),api.emit(\"transferFromContract\",{from:from,to:finalTo,symbol:symbol,quantity:quantity}))}}}}}};const
|
224
|
+
processUnstake=async unstake=>{const{account:account,symbol:symbol,quantity:quantity,quantityLeft:quantityLeft,numberTransactionsLeft:numberTransactionsLeft}=unstake,newUnstake=unstake,balance=await
|
225
|
+
api.db.findOne(\"balances\",{account:account,symbol:symbol}),token=await api.db.findOne(\"tokens\",{symbol:symbol});let
|
226
|
+
tokensToRelease=0;if(api.assert(null!==balance,\"balance does not exist\")&&(1===numberTransactionsLeft?(tokensToRelease=quantityLeft,await
|
227
|
+
api.db.remove(\"pendingUnstakes\",unstake)):(tokensToRelease=api.BigNumber(quantity).dividedBy(token.numberTransactions).toFixed(token.precision,api.BigNumber.ROUND_DOWN),newUnstake.quantityLeft=api.BigNumber(newUnstake.quantityLeft).minus(tokensToRelease).toFixed(token.precision),newUnstake.numberTransactionsLeft-=1,newUnstake.nextTransactionTimestamp=api.BigNumber(newUnstake.nextTransactionTimestamp).plus(newUnstake.millisecPerPeriod).toNumber(),await
|
228
|
+
api.db.update(\"pendingUnstakes\",newUnstake)),api.BigNumber(tokensToRelease).gt(0))){const
|
229
|
+
originalBalance=balance.balance,originalPendingStake=balance.pendingUnstake;balance.balance=calculateBalance(balance.balance,tokensToRelease,token.precision,!0),balance.pendingUnstake=calculateBalance(balance.pendingUnstake,tokensToRelease,token.precision,!1),api.assert(api.BigNumber(balance.pendingUnstake).lt(originalPendingStake)&&api.BigNumber(balance.balance).gt(originalBalance),\"cannot
|
230
|
+
subtract\")&&(await api.db.update(\"balances\",balance),token.totalStaked=calculateBalance(token.totalStaked,tokensToRelease,token.precision,!1),await
|
231
|
+
api.db.update(\"tokens\",token),api.emit(\"unstake\",{account:account,symbol:symbol,quantity:tokensToRelease}),\"ENG\"===symbol&&await
|
232
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:account}))}};actions.checkPendingUnstakes=async()=>{if(api.assert(\"null\"===api.sender,\"not
|
233
|
+
authorized\")){const timestamp=new Date(api.steemBlockTimestamp+\".000Z\").getTime();let
|
234
|
+
pendingUnstakes=await api.db.find(\"pendingUnstakes\",{nextTransactionTimestamp:{$lte:timestamp}}),nbPendingUnstakes=pendingUnstakes.length;for(;nbPendingUnstakes>0;){for(let
|
235
|
+
index=0;index<nbPendingUnstakes;index+=1){const pendingUnstake=pendingUnstakes[index];await
|
236
|
+
processUnstake(pendingUnstake)}pendingUnstakes=await api.db.find(\"pendingUnstakes\",{nextTransactionTimestamp:{$lte:timestamp}}),nbPendingUnstakes=pendingUnstakes.length}}},actions.enableStaking=async
|
237
|
+
payload=>{const{symbol:symbol,unstakingCooldown:unstakingCooldown,numberTransactions:numberTransactions,isSignedWithActiveKey:isSignedWithActiveKey}=payload,params=await
|
238
|
+
api.db.findOne(\"params\",{}),{enableStakingFee:enableStakingFee}=params,utilityTokenBalance=await
|
239
|
+
api.db.findOne(\"balances\",{account:api.sender,symbol:\"ENG\"}),enoughFunds=utilityTokenBalance&&api.BigNumber(utilityTokenBalance.balance).gte(enableStakingFee),authorized=void
|
240
|
+
0===enableStakingFee||api.BigNumber(enableStakingFee).lte(0)||enoughFunds;if(api.assert(authorized,\"you
|
241
|
+
must have enough tokens to cover fees\")&&api.assert(!0===isSignedWithActiveKey,\"you
|
242
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
243
|
+
symbol,\"invalid symbol\")&&api.assert(unstakingCooldown&&Number.isInteger(unstakingCooldown)&&unstakingCooldown>0&&unstakingCooldown<=18250,\"unstakingCooldown
|
244
|
+
must be an integer between 1 and 18250\")&&api.assert(numberTransactions&&Number.isInteger(numberTransactions)&&numberTransactions>0&&numberTransactions<=18250,\"numberTransactions
|
245
|
+
must be an integer between 1 and 18250\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});api.assert(null!==token,\"symbol
|
246
|
+
does not exist\")&&api.assert(token.issuer===api.sender,\"must be the issuer\")&&api.assert(void
|
247
|
+
0===token.stakingEnabled||!1===token.stakingEnabled,\"staking already enabled\")&&(token.stakingEnabled=!0,token.totalStaked=\"0\",token.unstakingCooldown=unstakingCooldown,token.numberTransactions=numberTransactions,await
|
248
|
+
api.db.update(\"tokens\",token),api.BigNumber(enableStakingFee).gt(0)&&await
|
249
|
+
actions.transfer({to:\"null\",symbol:\"ENG\",quantity:enableStakingFee,isSignedWithActiveKey:isSignedWithActiveKey}))}},actions.stake=async
|
250
|
+
payload=>{const{symbol:symbol,quantity:quantity,to:to,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
251
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
252
|
+
symbol&&to&&\"string\"==typeof to&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
253
|
+
params\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol}),finalTo=to.trim();if(api.assert(api.isValidAccountName(finalTo),\"invalid
|
254
|
+
to\")&&api.assert(null!==token,\"symbol does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
255
|
+
precision mismatch\")&&api.assert(!0===token.stakingEnabled,\"staking not
|
256
|
+
enabled\")&&api.assert(api.BigNumber(quantity).gt(0),\"must stake positive
|
257
|
+
quantity\")&&await subBalance(api.sender,token,quantity,\"balances\")){!1===await
|
258
|
+
addStake(finalTo,token,quantity)?await addBalance(api.sender,token,quantity,\"balances\"):(api.emit(\"stake\",{account:finalTo,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&await
|
259
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:api.sender}))}}},actions.stakeFromContract=async
|
260
|
+
payload=>{const{symbol:symbol,quantity:quantity,to:to,callingContractInfo:callingContractInfo}=payload;if(callingContractInfo&&api.assert(symbol&&\"string\"==typeof
|
261
|
+
symbol&&to&&\"string\"==typeof to&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
262
|
+
params\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol}),finalTo=to.trim();if(api.assert(api.isValidAccountName(finalTo),\"invalid
|
263
|
+
to\")&&api.assert(null!==token,\"symbol does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
264
|
+
precision mismatch\")&&api.assert(!0===token.stakingEnabled,\"staking not
|
265
|
+
enabled\")&&api.assert(api.BigNumber(quantity).gt(0),\"must stake positive
|
266
|
+
quantity\")&&await subBalance(callingContractInfo.name,token,quantity,\"contractsBalances\")){!1===await
|
267
|
+
addStake(finalTo,token,quantity)?await addBalance(callingContractInfo.name,token,quantity,\"balances\"):(api.emit(\"stakeFromContract\",{account:finalTo,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&await
|
268
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:finalTo}))}}};const
|
269
|
+
startUnstake=async(account,token,quantity)=>{const blockDate=new Date(api.steemBlockTimestamp+\".000Z\"),cooldownPeriodMillisec=24*token.unstakingCooldown*3600*1e3,millisecPerPeriod=api.BigNumber(cooldownPeriodMillisec).dividedBy(token.numberTransactions).integerValue(api.BigNumber.ROUND_DOWN),nextTransactionTimestamp=api.BigNumber(blockDate.getTime()).plus(millisecPerPeriod).toNumber(),unstake={account:account,symbol:token.symbol,quantity:quantity,quantityLeft:quantity,nextTransactionTimestamp:nextTransactionTimestamp,numberTransactionsLeft:token.numberTransactions,millisecPerPeriod:millisecPerPeriod,txID:api.transactionId};await
|
270
|
+
api.db.insert(\"pendingUnstakes\",unstake)};actions.unstake=async payload=>{const{symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
271
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
272
|
+
symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
273
|
+
params\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});api.assert(null!==token,\"symbol
|
274
|
+
does not exist\")&&api.assert(!0===token.stakingEnabled,\"staking not enabled\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
275
|
+
precision mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must unstake
|
276
|
+
positive quantity\")&&await subStake(api.sender,token,quantity)&&(await startUnstake(api.sender,token,quantity),api.emit(\"unstakeStart\",{account:api.sender,symbol:symbol,quantity:quantity}))}};const
|
277
|
+
processCancelUnstake=async unstake=>{const{account:account,symbol:symbol,quantityLeft:quantityLeft}=unstake,balance=await
|
278
|
+
api.db.findOne(\"balances\",{account:account,symbol:symbol}),token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==balance,\"balance
|
279
|
+
does not exist\")&&api.assert(api.BigNumber(balance.pendingUnstake).gte(quantityLeft),\"overdrawn
|
280
|
+
pendingUnstake\")){const originalStake=balance.stake,originalPendingStake=balance.pendingUnstake;if(balance.stake=calculateBalance(balance.stake,quantityLeft,token.precision,!0),balance.pendingUnstake=calculateBalance(balance.pendingUnstake,quantityLeft,token.precision,!1),api.assert(api.BigNumber(balance.pendingUnstake).lt(originalPendingStake)&&api.BigNumber(balance.stake).gt(originalStake),\"cannot
|
281
|
+
subtract\"))return await api.db.update(\"balances\",balance),api.emit(\"unstake\",{account:account,symbol:symbol,quantity:quantityLeft}),!0}return!1};actions.cancelUnstake=async
|
282
|
+
payload=>{const{txID:txID,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
283
|
+
must use a custom_json signed with your active key\")&&api.assert(txID&&\"string\"==typeof
|
284
|
+
txID,\"invalid params\")){const unstake=await api.db.findOne(\"pendingUnstakes\",{account:api.sender,txID:txID});api.assert(unstake,\"unstake
|
285
|
+
does not exist\")&&await processCancelUnstake(unstake)&&await api.db.remove(\"pendingUnstakes\",unstake)}},actions.enableDelegation=async
|
286
|
+
payload=>{const{symbol:symbol,undelegationCooldown:undelegationCooldown,isSignedWithActiveKey:isSignedWithActiveKey}=payload,params=await
|
287
|
+
api.db.findOne(\"params\",{}),{enableDelegationFee:enableDelegationFee}=params,utilityTokenBalance=await
|
288
|
+
api.db.findOne(\"balances\",{account:api.sender,symbol:\"ENG\"}),enoughFunds=utilityTokenBalance&&api.BigNumber(utilityTokenBalance.balance).gte(enableDelegationFee),authorized=void
|
289
|
+
0===enableDelegationFee||api.BigNumber(enableDelegationFee).lte(0)||enoughFunds;if(api.assert(authorized,\"you
|
290
|
+
must have enough tokens to cover fees\")&&api.assert(!0===isSignedWithActiveKey,\"you
|
291
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
292
|
+
symbol,\"invalid symbol\")&&api.assert(undelegationCooldown&&Number.isInteger(undelegationCooldown)&&undelegationCooldown>0&&undelegationCooldown<=18250,\"undelegationCooldown
|
293
|
+
must be an integer between 1 and 18250\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});api.assert(null!==token,\"symbol
|
294
|
+
does not exist\")&&api.assert(token.issuer===api.sender,\"must be the issuer\")&&api.assert(!0===token.stakingEnabled,\"staking
|
295
|
+
not enabled\")&&api.assert(void 0===token.delegationEnabled||!1===token.delegationEnabled,\"delegation
|
296
|
+
already enabled\")&&(token.delegationEnabled=!0,token.undelegationCooldown=undelegationCooldown,await
|
297
|
+
api.db.update(\"tokens\",token),api.BigNumber(enableDelegationFee).gt(0)&&await
|
298
|
+
actions.transfer({to:\"null\",symbol:\"ENG\",quantity:enableDelegationFee,isSignedWithActiveKey:isSignedWithActiveKey}))}},actions.delegate=async
|
299
|
+
payload=>{const{symbol:symbol,quantity:quantity,to:to,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
300
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
301
|
+
symbol&&to&&\"string\"==typeof to&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
302
|
+
params\")){const finalTo=to.trim();if(api.assert(api.isValidAccountName(finalTo),\"invalid
|
303
|
+
to\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
304
|
+
does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
305
|
+
precision mismatch\")&&api.assert(!0===token.delegationEnabled,\"delegation
|
306
|
+
not enabled\")&&api.assert(finalTo!==api.sender,\"cannot delegate to yourself\")&&api.assert(api.BigNumber(quantity).gt(0),\"must
|
307
|
+
delegate positive quantity\")){const balanceFrom=await api.db.findOne(\"balances\",{account:api.sender,symbol:symbol});if(api.assert(null!==balanceFrom,\"balanceFrom
|
308
|
+
does not exist\")&&api.assert(api.BigNumber(balanceFrom.stake).gte(quantity),\"overdrawn
|
309
|
+
stake\")){void 0===balanceFrom.stake?(balanceFrom.stake=\"0\",balanceFrom.pendingUnstake=\"0\",balanceFrom.delegationsIn=\"0\",balanceFrom.delegationsOut=\"0\",balanceFrom.pendingUndelegations=\"0\"):void
|
310
|
+
0===balanceFrom.delegationsIn&&(balanceFrom.delegationsIn=\"0\",balanceFrom.delegationsOut=\"0\",balanceFrom.pendingUndelegations=\"0\",balanceFrom.delegatedStake&&(delete
|
311
|
+
balanceFrom.delegatedStake,delete balanceFrom.receivedStake));let balanceTo=await
|
312
|
+
api.db.findOne(\"balances\",{account:finalTo,symbol:symbol});null===balanceTo?(balanceTo=balanceTemplate,balanceTo.account=finalTo,balanceTo.symbol=symbol,balanceTo=await
|
313
|
+
api.db.insert(\"balances\",balanceTo)):void 0===balanceTo.stake?(balanceTo.stake=\"0\",balanceTo.pendingUnstake=\"0\",balanceTo.delegationsIn=\"0\",balanceTo.delegationsOut=\"0\",balanceTo.pendingUndelegations=\"0\"):void
|
314
|
+
0===balanceTo.delegationsIn&&(balanceTo.delegationsIn=\"0\",balanceTo.delegationsOut=\"0\",balanceTo.pendingUndelegations=\"0\",balanceTo.delegatedStake&&(delete
|
315
|
+
balanceTo.delegatedStake,delete balanceTo.receivedStake));let delegation=await
|
316
|
+
api.db.findOne(\"delegations\",{to:finalTo,from:api.sender,symbol:symbol});const
|
317
|
+
timestamp=new Date(api.steemBlockTimestamp+\".000Z\").getTime();null==delegation?(balanceFrom.stake=calculateBalance(balanceFrom.stake,quantity,token.precision,!1),balanceFrom.delegationsOut=calculateBalance(balanceFrom.delegationsOut,quantity,token.precision,!0),await
|
318
|
+
api.db.update(\"balances\",balanceFrom),balanceTo.delegationsIn=calculateBalance(balanceTo.delegationsIn,quantity,token.precision,!0),await
|
319
|
+
api.db.update(\"balances\",balanceTo),delegation={},delegation.from=api.sender,delegation.to=finalTo,delegation.symbol=symbol,delegation.quantity=quantity,delegation.created=timestamp,delegation.updated=timestamp,await
|
320
|
+
api.db.insert(\"delegations\",delegation),api.emit(\"delegate\",{to:finalTo,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&(await
|
321
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:api.sender}),await
|
322
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:finalTo}))):(balanceFrom.stake=calculateBalance(balanceFrom.stake,quantity,token.precision,!1),balanceFrom.delegationsOut=calculateBalance(balanceFrom.delegationsOut,quantity,token.precision,!0),await
|
323
|
+
api.db.update(\"balances\",balanceFrom),balanceTo.delegationsIn=calculateBalance(balanceTo.delegationsIn,quantity,token.precision,!0),await
|
324
|
+
api.db.update(\"balances\",balanceTo),delegation.quantity=calculateBalance(delegation.quantity,quantity,token.precision,!0),delegation.updated=timestamp,await
|
325
|
+
api.db.update(\"delegations\",delegation),api.emit(\"delegate\",{to:finalTo,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&(await
|
326
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:api.sender}),await
|
327
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:finalTo})))}}}}},actions.undelegate=async
|
328
|
+
payload=>{const{symbol:symbol,quantity:quantity,from:from,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
329
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
330
|
+
symbol&&from&&\"string\"==typeof from&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
331
|
+
params\")){const finalFrom=from.trim();if(api.assert(finalFrom.length>=3&&finalFrom.length<=16,\"invalid
|
332
|
+
from\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
333
|
+
does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
334
|
+
precision mismatch\")&&api.assert(!0===token.delegationEnabled,\"delegation
|
335
|
+
not enabled\")&&api.assert(finalFrom!==api.sender,\"cannot undelegate from
|
336
|
+
yourself\")&&api.assert(api.BigNumber(quantity).gt(0),\"must undelegate positive
|
337
|
+
quantity\")){const balanceTo=await api.db.findOne(\"balances\",{account:api.sender,symbol:symbol});if(api.assert(null!==balanceTo,\"balanceTo
|
338
|
+
does not exist\")&&api.assert(api.BigNumber(balanceTo.delegationsOut).gte(quantity),\"overdrawn
|
339
|
+
delegation\")){const balanceFrom=await api.db.findOne(\"balances\",{account:finalFrom,symbol:symbol});if(api.assert(null!==balanceFrom,\"balanceFrom
|
340
|
+
does not exist\")){const delegation=await api.db.findOne(\"delegations\",{to:finalFrom,from:api.sender,symbol:symbol});if(api.assert(null!==delegation,\"delegation
|
341
|
+
does not exist\")&&api.assert(api.BigNumber(delegation.quantity).gte(quantity),\"overdrawn
|
342
|
+
delegation\")){balanceTo.pendingUndelegations=calculateBalance(balanceFrom.pendingUndelegations,quantity,token.precision,!0),balanceTo.delegationsOut=calculateBalance(balanceTo.delegationsOut,quantity,token.precision,!1),await
|
343
|
+
api.db.update(\"balances\",balanceTo),balanceFrom.delegationsIn=calculateBalance(balanceFrom.delegationsIn,quantity,token.precision,!1),await
|
344
|
+
api.db.update(\"balances\",balanceFrom),delegation.quantity=calculateBalance(delegation.quantity,quantity,token.precision,!1),api.BigNumber(delegation.quantity).gt(0)?await
|
345
|
+
api.db.update(\"delegations\",delegation):await api.db.remove(\"delegations\",delegation);const
|
346
|
+
blockDate=new Date(api.steemBlockTimestamp+\".000Z\"),cooldownPeriodMillisec=24*token.undelegationCooldown*3600*1e3,completeTimestamp=blockDate.getTime()+cooldownPeriodMillisec,undelegation={account:api.sender,symbol:token.symbol,quantity:quantity,completeTimestamp:completeTimestamp,txID:api.transactionId};await
|
347
|
+
api.db.insert(\"pendingUndelegations\",undelegation),api.emit(\"undelegateStart\",{from:finalFrom,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&await
|
348
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:finalFrom})}}}}}}};const
|
349
|
+
processUndelegation=async undelegation=>{const{account:account,symbol:symbol,quantity:quantity}=undelegation,balance=await
|
350
|
+
api.db.findOne(\"balances\",{account:account,symbol:symbol}),token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==balance,\"balance
|
351
|
+
does not exist\")){const originalStake=balance.stake,originalPendingUndelegations=balance.pendingUndelegations;balance.stake=calculateBalance(balance.stake,quantity,token.precision,!0),balance.pendingUndelegations=calculateBalance(balance.pendingUndelegations,quantity,token.precision,!1),api.assert(api.BigNumber(balance.pendingUndelegations).lt(originalPendingUndelegations)&&api.BigNumber(balance.stake).gt(originalStake),\"cannot
|
352
|
+
subtract\")&&(await api.db.update(\"balances\",balance),await api.db.remove(\"pendingUndelegations\",undelegation),api.emit(\"undelegateDone\",{account:account,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&await
|
353
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:account}))}};actions.checkPendingUndelegations=async()=>{if(api.assert(\"null\"===api.sender,\"not
|
354
|
+
authorized\")){const timestamp=new Date(api.steemBlockTimestamp+\".000Z\").getTime();let
|
355
|
+
pendingUndelegations=await api.db.find(\"pendingUndelegations\",{completeTimestamp:{$lte:timestamp}}),nbPendingUndelegations=pendingUndelegations.length;for(;nbPendingUndelegations>0;){for(let
|
356
|
+
index=0;index<nbPendingUndelegations;index+=1){const pendingUndelegation=pendingUndelegations[index];await
|
357
|
+
processUndelegation(pendingUndelegation)}pendingUndelegations=await api.db.find(\"pendingUndelegations\",{completeTimestamp:{$lte:timestamp}}),nbPendingUndelegations=pendingUndelegations.length}}};\n \n const
|
358
|
+
execute = async function () {\n try {\n if (api.action
|
359
|
+
&& typeof api.action === ''string'' && typeof actions[api.action] === ''function'')
|
360
|
+
{\n if (api.action !== ''createSSC'') {\n actions.createSSC
|
361
|
+
= null;\n }\n await actions[api.action](api.payload);\n done(null);\n }
|
362
|
+
else {\n done(''invalid action'');\n }\n }
|
363
|
+
catch (error) {\n done(error);\n }\n }\n \n execute();\n }\n\n wrapper();\n ","codeHash":"d3ab1afa743f5322eb1b5da7ada99c43f7d26f47cfaab98acb9322c929b23ea6","tables":{"tokens_tokens":{"size":0,"hash":"92bff87e97d3aec60cdaed572a6fc2c536446720b19b8adb7873106a07374a8c","nbIndexes":1},"tokens_balances":{"size":0,"hash":"36bb20b060e3c705912577ea7e81b2f11042a04a90f423f2faad4d3c3f1dd9b4","nbIndexes":1},"tokens_contractsBalances":{"size":0,"hash":"b93b318af9260e030ef87e0ebdc3fdce0fbc4a8876bd3c1c1088d3a6d14f31b8","nbIndexes":1},"tokens_params":{"size":0,"hash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","nbIndexes":0},"tokens_pendingUnstakes":{"size":0,"hash":"8ee3bc30f2605c96a530ef6d48210c8a676d477fc41d56e398afeea9d51c2fa8","nbIndexes":2},"tokens_delegations":{"size":0,"hash":"a27c8e5de851e347042bb4de5c9657ad3f585692ab5b3c05ae4029b50ddf6a00","nbIndexes":2},"tokens_pendingUndelegations":{"size":0,"hash":"2389e37708da5577e80789021135fd74c4a84f1c693465dc71478aaa6d1456bb","nbIndexes":2}},"version":17}}'
|
364
|
+
http_version:
|
365
|
+
recorded_at: Sat, 17 Oct 2020 04:07:50 GMT
|
366
|
+
recorded_with: VCR 5.0.0
|