radiator 0.4.6 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +27 -12
- data/Rakefile +53 -23
- data/lib/radiator.rb +3 -1
- data/lib/radiator/api.rb +111 -16
- data/lib/radiator/bridge.rb +34 -0
- data/lib/radiator/broadcast_operations.json +7 -7
- data/lib/radiator/chain.rb +1 -1
- data/lib/radiator/chain_config.rb +9 -2
- data/lib/radiator/database_api.rb +1 -1
- data/lib/radiator/error_parser.rb +1 -1
- data/lib/radiator/follow_api.rb +1 -1
- data/lib/radiator/market_history_api.rb +1 -1
- data/lib/radiator/mixins/acts_as_poster.rb +4 -4
- 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 +1 -1
- data/lib/radiator/stream.rb +21 -8
- data/lib/radiator/transaction.rb +43 -3
- data/lib/radiator/type/amount.rb +8 -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 +17 -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 +1465 -0
- data/test/fixtures/vcr_cassettes/account_by_key_api_jsonrpc.yml +199 -0
- data/test/fixtures/vcr_cassettes/api_all_methods.yml +13802 -0
- data/test/fixtures/vcr_cassettes/api_jsonrpc.yml +53 -0
- data/test/fixtures/vcr_cassettes/base_per_debt.yml +11068 -0
- data/test/fixtures/vcr_cassettes/base_per_mvest.yml +6024 -0
- data/test/fixtures/vcr_cassettes/block_time.yml +5368 -0
- data/test/fixtures/vcr_cassettes/broadcast_transaction.yml +1723 -0
- data/test/fixtures/vcr_cassettes/chain_stats_api_jsonrpc.yml +51 -0
- data/test/fixtures/vcr_cassettes/condenser_all_all_methods.yml +13770 -0
- data/test/fixtures/vcr_cassettes/condenser_api_jsonrpc.yml +103 -0
- data/test/fixtures/vcr_cassettes/expiration_initialize.yml +16108 -0
- data/test/fixtures/vcr_cassettes/find_account.yml +5732 -0
- data/test/fixtures/vcr_cassettes/find_block.yml +5322 -0
- data/test/fixtures/vcr_cassettes/find_comment.yml +16386 -0
- data/test/fixtures/vcr_cassettes/follow_api_jsonrpc.yml +99 -0
- data/test/fixtures/vcr_cassettes/get_account_count.yml +783 -0
- data/test/fixtures/vcr_cassettes/get_account_references.yml +773 -0
- data/test/fixtures/vcr_cassettes/get_accounts.yml +918 -0
- data/test/fixtures/vcr_cassettes/get_accounts_no_argument.yml +773 -0
- data/test/fixtures/vcr_cassettes/get_dynamic_global_properties.yml +893 -0
- data/test/fixtures/vcr_cassettes/get_feed_history.yml +1432 -0
- data/test/fixtures/vcr_cassettes/get_hardfork_version.yml +835 -0
- data/test/fixtures/vcr_cassettes/get_key_references.yml +1571 -0
- data/test/fixtures/vcr_cassettes/get_market_history.yml +1563 -0
- data/test/fixtures/vcr_cassettes/get_market_history_buckets.yml +1665 -0
- data/test/fixtures/vcr_cassettes/get_order_book.yml +1459 -0
- data/test/fixtures/vcr_cassettes/get_recent_trades.yml +1459 -0
- data/test/fixtures/vcr_cassettes/get_ticker.yml +1563 -0
- data/test/fixtures/vcr_cassettes/get_trade_history.yml +1459 -0
- data/test/fixtures/vcr_cassettes/get_vesting_delegations.yml +731 -0
- data/test/fixtures/vcr_cassettes/get_volume.yml +1561 -0
- data/test/fixtures/vcr_cassettes/get_witness_by_account.yml +835 -0
- data/test/fixtures/vcr_cassettes/look_up_witnesses.yml +831 -0
- data/test/fixtures/vcr_cassettes/market_history_api_all_methods.yml +10191 -0
- data/test/fixtures/vcr_cassettes/market_history_api_jsonrpc.yml +51 -0
- data/test/fixtures/vcr_cassettes/network_broadcast_api_all_methods.yml +2455 -0
- data/test/fixtures/vcr_cassettes/network_broadcast_api_jsonrpc.yml +51 -0
- data/test/fixtures/vcr_cassettes/properties.yml +5551 -0
- data/test/fixtures/vcr_cassettes/recover_transaction.yml +1815 -0
- data/test/fixtures/vcr_cassettes/ssc_blockchain_block_info.yml +90 -0
- data/test/fixtures/vcr_cassettes/ssc_blockchain_block_info_invalid.yml +88 -0
- data/test/fixtures/vcr_cassettes/ssc_blockchain_latest_block_info.yml +90 -0
- data/test/fixtures/vcr_cassettes/ssc_blockchain_transaction_info.yml +90 -0
- data/test/fixtures/vcr_cassettes/ssc_contracts_contract.yml +364 -0
- data/test/fixtures/vcr_cassettes/ssc_contracts_find.yml +89 -0
- data/test/fixtures/vcr_cassettes/ssc_contracts_find_one.yml +87 -0
- data/test/fixtures/vcr_cassettes/stream_jsonrpc.yml +27502 -0
- data/test/fixtures/vcr_cassettes/tag_api_jsonrpc.yml +155 -0
- data/test/fixtures/vcr_cassettes/transaction_expiration_initialize_nil.yml +17597 -0
- data/test/fixtures/vcr_cassettes/transaction_jsonrpc.yml +61 -0
- data/test/fixtures/vcr_cassettes/unknown_chain_id.yml +13038 -0
- data/test/fixtures/vcr_cassettes/valid_chains.yml +11450 -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 +116 -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 +187 -79
- 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,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.2
|
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, 07 Nov 2020 19:33:43 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
|
+
recorded_at: Sat, 07 Nov 2020 19:33:43 GMT
|
45
|
+
- request:
|
46
|
+
method: post
|
47
|
+
uri: https://api.steem-engine.com/rpc/blockchain
|
48
|
+
body:
|
49
|
+
encoding: UTF-8
|
50
|
+
string: '{"method":"getBlockInfo","params":{"blockNumber":1},"jsonrpc":"2.0","id":1}'
|
51
|
+
headers:
|
52
|
+
Content-Type:
|
53
|
+
- application/json
|
54
|
+
User-Agent:
|
55
|
+
- radiator/0.4.8.pre.2
|
56
|
+
Accept-Encoding:
|
57
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
58
|
+
Accept:
|
59
|
+
- "*/*"
|
60
|
+
Connection:
|
61
|
+
- keep-alive
|
62
|
+
Keep-Alive:
|
63
|
+
- '30'
|
64
|
+
response:
|
65
|
+
status:
|
66
|
+
code: 200
|
67
|
+
message: OK
|
68
|
+
headers:
|
69
|
+
Server:
|
70
|
+
- nginx/1.10.3 (Ubuntu)
|
71
|
+
Date:
|
72
|
+
- Sat, 07 Nov 2020 19:33:43 GMT
|
73
|
+
Content-Type:
|
74
|
+
- application/json; charset=utf-8
|
75
|
+
Transfer-Encoding:
|
76
|
+
- chunked
|
77
|
+
Connection:
|
78
|
+
- keep-alive
|
79
|
+
Vary:
|
80
|
+
- Accept-Encoding
|
81
|
+
X-Powered-By:
|
82
|
+
- Express
|
83
|
+
Access-Control-Allow-Origin:
|
84
|
+
- "*"
|
85
|
+
body:
|
86
|
+
encoding: ASCII-8BIT
|
87
|
+
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
|
88
|
+
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"}}'
|
89
|
+
recorded_at: Sat, 07 Nov 2020 19:33:43 GMT
|
90
|
+
recorded_with: VCR 6.0.0
|
@@ -0,0 +1,88 @@
|
|
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.2
|
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, 07 Nov 2020 19:33: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
|
+
recorded_at: Sat, 07 Nov 2020 19:33:44 GMT
|
45
|
+
- request:
|
46
|
+
method: post
|
47
|
+
uri: https://api.steem-engine.com/rpc/blockchain
|
48
|
+
body:
|
49
|
+
encoding: UTF-8
|
50
|
+
string: '{"method":"getBlockInfo","params":{"blockNumber":"WRONG"},"jsonrpc":"2.0","id":1}'
|
51
|
+
headers:
|
52
|
+
Content-Type:
|
53
|
+
- application/json
|
54
|
+
User-Agent:
|
55
|
+
- radiator/0.4.8.pre.2
|
56
|
+
Accept-Encoding:
|
57
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
58
|
+
Accept:
|
59
|
+
- "*/*"
|
60
|
+
Connection:
|
61
|
+
- keep-alive
|
62
|
+
Keep-Alive:
|
63
|
+
- '30'
|
64
|
+
response:
|
65
|
+
status:
|
66
|
+
code: 200
|
67
|
+
message: OK
|
68
|
+
headers:
|
69
|
+
Server:
|
70
|
+
- nginx/1.10.3 (Ubuntu)
|
71
|
+
Date:
|
72
|
+
- Sat, 07 Nov 2020 19:33:45 GMT
|
73
|
+
Content-Type:
|
74
|
+
- application/json; charset=utf-8
|
75
|
+
Content-Length:
|
76
|
+
- '110'
|
77
|
+
Connection:
|
78
|
+
- keep-alive
|
79
|
+
X-Powered-By:
|
80
|
+
- Express
|
81
|
+
Access-Control-Allow-Origin:
|
82
|
+
- "*"
|
83
|
+
body:
|
84
|
+
encoding: UTF-8
|
85
|
+
string: '{"jsonrpc":"2.0","id":1,"error":{"code":400,"message":"missing or wrong
|
86
|
+
parameters: blockNumber is required"}}'
|
87
|
+
recorded_at: Sat, 07 Nov 2020 19:33:45 GMT
|
88
|
+
recorded_with: VCR 6.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.2
|
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, 07 Nov 2020 19:33: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
|
+
recorded_at: Sat, 07 Nov 2020 19:33:40 GMT
|
45
|
+
- request:
|
46
|
+
method: post
|
47
|
+
uri: https://api.steem-engine.com/rpc/blockchain
|
48
|
+
body:
|
49
|
+
encoding: UTF-8
|
50
|
+
string: '{"method":"getLatestBlockInfo","jsonrpc":"2.0","id":1}'
|
51
|
+
headers:
|
52
|
+
Content-Type:
|
53
|
+
- application/json
|
54
|
+
User-Agent:
|
55
|
+
- radiator/0.4.8.pre.2
|
56
|
+
Accept-Encoding:
|
57
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
58
|
+
Accept:
|
59
|
+
- "*/*"
|
60
|
+
Connection:
|
61
|
+
- keep-alive
|
62
|
+
Keep-Alive:
|
63
|
+
- '30'
|
64
|
+
response:
|
65
|
+
status:
|
66
|
+
code: 200
|
67
|
+
message: OK
|
68
|
+
headers:
|
69
|
+
Server:
|
70
|
+
- nginx/1.10.3 (Ubuntu)
|
71
|
+
Date:
|
72
|
+
- Sat, 07 Nov 2020 19:33:40 GMT
|
73
|
+
Content-Type:
|
74
|
+
- application/json; charset=utf-8
|
75
|
+
Transfer-Encoding:
|
76
|
+
- chunked
|
77
|
+
Connection:
|
78
|
+
- keep-alive
|
79
|
+
Vary:
|
80
|
+
- Accept-Encoding
|
81
|
+
X-Powered-By:
|
82
|
+
- Express
|
83
|
+
Access-Control-Allow-Origin:
|
84
|
+
- "*"
|
85
|
+
body:
|
86
|
+
encoding: ASCII-8BIT
|
87
|
+
string: '{"jsonrpc":"2.0","id":1,"result":{"_id":8146292,"blockNumber":8146292,"refSteemBlockNumber":48403718,"refSteemBlockId":"02e29506946bfc076394598496fef7246b5dd870","prevRefSteemBlockId":"02e29505e4bdabc8dcf75b6152f8cc3c8ba7128b","previousHash":"8f75094d6963b595407954686534721ce369e1b28b226b31fc0be1df5e584bde","previousDatabaseHash":"cc2596aa23d3ff1e9fc1b4a329b31d3dbc7f7d113d806952d33e950a7551e9ad","timestamp":"2020-11-07T19:33:21","transactions":[{"refSteemBlockNumber":48403718,"transactionId":"c9cc5353d0252879adf24643f34c9cc2a54f4919-0","sender":"dliker","contract":"tokens","action":"issue","payload":"{\"symbol\":\"DLIKER\",\"to\":\"dliker\",\"quantity\":\"1008.781\",\"isSignedWithActiveKey\":true}","executedCodeHash":"d3ab1afa743f5322eb1b5da7ada99c43f7d26f47cfaab98acb9322c929b23ea6","hash":"2b6ac59f8166afc09d26e536330a71a0e507214fc81be0cae9a69f9957abe7c8","databaseHash":"1b0f2d22bd00e56afc9015850b40eeb8ba9bb48d440a19308422714d3a21f292","logs":"{\"events\":[{\"contract\":\"tokens\",\"event\":\"transferFromContract\",\"data\":{\"from\":\"tokens\",\"to\":\"dliker\",\"symbol\":\"DLIKER\",\"quantity\":\"1008.781\"}}]}"},{"refSteemBlockNumber":48403718,"transactionId":"c9cc5353d0252879adf24643f34c9cc2a54f4919-1","sender":"dliker","contract":"tokens","action":"stake","payload":"{\"symbol\":\"DLIKER\",\"to\":\"tbnfl4sun\",\"quantity\":\"504.390\",\"isSignedWithActiveKey\":true}","executedCodeHash":"d3ab1afa743f5322eb1b5da7ada99c43f7d26f47cfaab98acb9322c929b23ea6","hash":"2ed37c33bacfc78f9f47a516b2844b275a0b27fd8a7dea14842f8e03cd5bf67f","databaseHash":"9015c3d4c28f81692644e8d2b9aa9c7b30a9891f55c1f4601e6fee6d671c5ecd","logs":"{\"events\":[{\"contract\":\"tokens\",\"event\":\"stake\",\"data\":{\"account\":\"tbnfl4sun\",\"symbol\":\"DLIKER\",\"quantity\":\"504.390\"}}]}"},{"refSteemBlockNumber":48403718,"transactionId":"c9cc5353d0252879adf24643f34c9cc2a54f4919-2","sender":"dliker","contract":"tokens","action":"transfer","payload":"{\"symbol\":\"DLIKER\",\"to\":\"tbnfl4sun\",\"quantity\":\"504.390\",\"memo\":\"Here
|
88
|
+
are your claimed tokens! (504.390500 more DLIKER were added to DLIKER POWER)\",\"isSignedWithActiveKey\":true}","executedCodeHash":"d3ab1afa743f5322eb1b5da7ada99c43f7d26f47cfaab98acb9322c929b23ea6","hash":"33ddd94da3f3adf1666de9adb0151eca81a7b3f98d2863867008747fb42ee9e8","databaseHash":"9463d12a686f2ab4b72f40baf6cda0ffc2ebebf513a8814302d6ffe585f1abc3","logs":"{\"events\":[{\"contract\":\"tokens\",\"event\":\"transfer\",\"data\":{\"from\":\"dliker\",\"to\":\"tbnfl4sun\",\"symbol\":\"DLIKER\",\"quantity\":\"504.390\"}}]}"}],"virtualTransactions":[],"hash":"e2a282778da768190ffa03297562c77bbdfa6a0a1528f70611a82c65811f7c2b","databaseHash":"48e90b0a80ff9e4ace9315e1e2e6773505da1177a7983bb17022fddf79d5be99","merkleRoot":"61fef3286db59ba957f884b083cb08bd852d25512c51fffa38322be5e76199fd","round":null,"roundHash":"","witness":"","signingKey":"","roundSignature":""}}'
|
89
|
+
recorded_at: Sat, 07 Nov 2020 19:33:41 GMT
|
90
|
+
recorded_with: VCR 6.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.2
|
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, 07 Nov 2020 19:33:41 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
|
+
recorded_at: Sat, 07 Nov 2020 19:33:41 GMT
|
45
|
+
- request:
|
46
|
+
method: post
|
47
|
+
uri: https://api.steem-engine.com/rpc/blockchain
|
48
|
+
body:
|
49
|
+
encoding: UTF-8
|
50
|
+
string: '{"method":"getTransactionInfo","params":{"txid":"df846ffdbd87f3fae2a60993dae9d16d44c814e3"},"jsonrpc":"2.0","id":1}'
|
51
|
+
headers:
|
52
|
+
Content-Type:
|
53
|
+
- application/json
|
54
|
+
User-Agent:
|
55
|
+
- radiator/0.4.8.pre.2
|
56
|
+
Accept-Encoding:
|
57
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
58
|
+
Accept:
|
59
|
+
- "*/*"
|
60
|
+
Connection:
|
61
|
+
- keep-alive
|
62
|
+
Keep-Alive:
|
63
|
+
- '30'
|
64
|
+
response:
|
65
|
+
status:
|
66
|
+
code: 200
|
67
|
+
message: OK
|
68
|
+
headers:
|
69
|
+
Server:
|
70
|
+
- nginx/1.10.3 (Ubuntu)
|
71
|
+
Date:
|
72
|
+
- Sat, 07 Nov 2020 19:33:42 GMT
|
73
|
+
Content-Type:
|
74
|
+
- application/json; charset=utf-8
|
75
|
+
Transfer-Encoding:
|
76
|
+
- chunked
|
77
|
+
Connection:
|
78
|
+
- keep-alive
|
79
|
+
Vary:
|
80
|
+
- Accept-Encoding
|
81
|
+
X-Powered-By:
|
82
|
+
- Express
|
83
|
+
Access-Control-Allow-Origin:
|
84
|
+
- "*"
|
85
|
+
body:
|
86
|
+
encoding: ASCII-8BIT
|
87
|
+
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
|
88
|
+
STEEM\",\"isSignedWithActiveKey\":true}","executedCodeHash":"2189984c5648194eb352aad01bb5b8235367a4c040c42b7d5bac107270e94c49986d043b17a3da825157d3edaec1f23d2cecb2637a1f1bbbdb4c66caa958797a","hash":"07bf1380f6339aa692009028376b3ca685f8b7d9a5a73893bf599f8612c99c2b","databaseHash":"bb464a0df58fa01162120bd37e64157495188d070ee4710d71488e9381a4156b","logs":"{\"events\":[{\"contract\":\"tokens\",\"event\":\"transfer\",\"data\":{\"from\":\"steemsc\",\"to\":\"yabapmatt\",\"symbol\":\"ENG\",\"quantity\":100}}]}"}}'
|
89
|
+
recorded_at: Sat, 07 Nov 2020 19:33:42 GMT
|
90
|
+
recorded_with: VCR 6.0.0
|
@@ -0,0 +1,364 @@
|
|
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.2
|
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, 07 Nov 2020 20:13:31 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
|
+
recorded_at: Sat, 07 Nov 2020 20:13:32 GMT
|
45
|
+
- request:
|
46
|
+
method: post
|
47
|
+
uri: https://api.steem-engine.com/rpc/contracts
|
48
|
+
body:
|
49
|
+
encoding: UTF-8
|
50
|
+
string: '{"method":"getContract","params":{"name":"tokens"},"jsonrpc":"2.0","id":1}'
|
51
|
+
headers:
|
52
|
+
Content-Type:
|
53
|
+
- application/json
|
54
|
+
User-Agent:
|
55
|
+
- radiator/0.4.8.pre.2
|
56
|
+
Accept-Encoding:
|
57
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
58
|
+
Accept:
|
59
|
+
- "*/*"
|
60
|
+
Connection:
|
61
|
+
- keep-alive
|
62
|
+
Keep-Alive:
|
63
|
+
- '30'
|
64
|
+
response:
|
65
|
+
status:
|
66
|
+
code: 200
|
67
|
+
message: OK
|
68
|
+
headers:
|
69
|
+
Server:
|
70
|
+
- nginx/1.10.3 (Ubuntu)
|
71
|
+
Date:
|
72
|
+
- Sat, 07 Nov 2020 20:13:32 GMT
|
73
|
+
Content-Type:
|
74
|
+
- application/json; charset=utf-8
|
75
|
+
Transfer-Encoding:
|
76
|
+
- chunked
|
77
|
+
Connection:
|
78
|
+
- keep-alive
|
79
|
+
Vary:
|
80
|
+
- Accept-Encoding
|
81
|
+
X-Powered-By:
|
82
|
+
- Express
|
83
|
+
Access-Control-Allow-Origin:
|
84
|
+
- "*"
|
85
|
+
body:
|
86
|
+
encoding: ASCII-8BIT
|
87
|
+
string: '{"jsonrpc":"2.0","id":1,"result":{"_id":"tokens","owner":"steemsc","code":"\n function
|
88
|
+
wrapper () {\n RegExp.prototype.constructor = function () { };\n RegExp.prototype.exec
|
89
|
+
= function () { };\n RegExp.prototype.test = function () { };\n \n let
|
90
|
+
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
|
91
|
+
tableExists=await api.db.tableExists(\"tokens\");if(!1===tableExists){await
|
92
|
+
api.db.createTable(\"tokens\",[\"symbol\"]),await api.db.createTable(\"balances\",[\"account\"]),await
|
93
|
+
api.db.createTable(\"contractsBalances\",[\"account\"]),await api.db.createTable(\"params\");const
|
94
|
+
params={tokenCreationFee:\"0\"};await api.db.insert(\"params\",params)}else{const
|
95
|
+
params=await api.db.findOne(\"params\",{});params.enableDelegationFee=\"1000\",params.enableStakingFee=\"1000\",await
|
96
|
+
api.db.update(\"params\",params)}tableExists=await api.db.tableExists(\"pendingUnstakes\"),!1===tableExists&&await
|
97
|
+
api.db.createTable(\"pendingUnstakes\",[\"account\",\"unstakeCompleteTimestamp\"]),tableExists=await
|
98
|
+
api.db.tableExists(\"delegations\"),!1===tableExists&&(await api.db.createTable(\"delegations\",[\"from\",\"to\"]),await
|
99
|
+
api.db.createTable(\"pendingUndelegations\",[\"account\",\"completeTimestamp\"]));let
|
100
|
+
token=await api.db.findOne(\"tokens\",{symbol:\"STEEMP\"});token&&token.precision<8&&(token.precision=8,await
|
101
|
+
api.db.update(\"tokens\",token)),token=await api.db.findOne(\"tokens\",{symbol:\"ENG\"}),void
|
102
|
+
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
|
103
|
+
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
|
104
|
+
balance=await api.db.findOne(\"balances\",{account:account,symbol:token.symbol});null===balance&&(balance=balanceTemplate,balance.account=account,balance.symbol=token.symbol,balance=await
|
105
|
+
api.db.insert(\"balances\",balance)),void 0===balance.stake&&(balance.stake=\"0\",balance.pendingUnstake=\"0\");const
|
106
|
+
originalStake=balance.stake;return balance.stake=calculateBalance(balance.stake,quantity,token.precision,!0),!!api.assert(api.BigNumber(balance.stake).gt(originalStake),\"cannot
|
107
|
+
add\")&&(await api.db.update(\"balances\",balance),void 0===token.totalStaked&&(token.totalStaked=\"0\"),token.totalStaked=calculateBalance(token.totalStaked,quantity,token.precision,!0),await
|
108
|
+
api.db.update(\"tokens\",token),!0)},subStake=async(account,token,quantity)=>{const
|
109
|
+
balance=await api.db.findOne(\"balances\",{account:account,symbol:token.symbol});if(api.assert(null!==balance,\"balance
|
110
|
+
does not exist\")&&api.assert(api.BigNumber(balance.stake).gte(quantity),\"overdrawn
|
111
|
+
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
|
112
|
+
subtract\"))return await api.db.update(\"balances\",balance),!0}return!1},subBalance=async(account,token,quantity,table)=>{const
|
113
|
+
balance=await api.db.findOne(table,{account:account,symbol:token.symbol});if(api.assert(null!==balance,\"balance
|
114
|
+
does not exist\")&&api.assert(api.BigNumber(balance.balance).gte(quantity),\"overdrawn
|
115
|
+
balance\")){const originalBalance=balance.balance;if(balance.balance=calculateBalance(balance.balance,quantity,token.precision,!1),api.assert(api.BigNumber(balance.balance).lt(originalBalance),\"cannot
|
116
|
+
subtract\"))return await api.db.update(table,balance),!0}return!1},addBalance=async(account,token,quantity,table)=>{let
|
117
|
+
balance=await api.db.findOne(table,{account:account,symbol:token.symbol});if(null===balance)return
|
118
|
+
balance=balanceTemplate,balance.account=account,balance.symbol=token.symbol,balance.balance=quantity,await
|
119
|
+
api.db.insert(table,balance),!0;const originalBalance=balance.balance;return
|
120
|
+
balance.balance=calculateBalance(balance.balance,quantity,token.precision,!0),!!api.assert(api.BigNumber(balance.balance).gt(originalBalance),\"cannot
|
121
|
+
add\")&&(await api.db.update(table,balance),!0)};actions.updateParams=async
|
122
|
+
payload=>{if(api.sender!==api.owner)return;const{tokenCreationFee:tokenCreationFee}=payload,params=await
|
123
|
+
api.db.findOne(\"params\",{});params.tokenCreationFee=tokenCreationFee,await
|
124
|
+
api.db.update(\"params\",params)},actions.updateUrl=async payload=>{const{url:url,symbol:symbol}=payload;if(api.assert(symbol&&\"string\"==typeof
|
125
|
+
symbol&&url&&\"string\"==typeof url,\"invalid params\")&&api.assert(url.length<=255,\"invalid
|
126
|
+
url: max length of 255\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(token&&api.assert(token.issuer===api.sender,\"must
|
127
|
+
be the issuer\"))try{const metadata=JSON.parse(token.metadata);api.assert(metadata&&metadata.url,\"an
|
128
|
+
error occured when trying to update the url\")&&(metadata.url=url,token.metadata=JSON.stringify(metadata),await
|
129
|
+
api.db.update(\"tokens\",token))}catch(e){}}},actions.updateMetadata=async
|
130
|
+
payload=>{const{metadata:metadata,symbol:symbol}=payload;if(api.assert(symbol&&\"string\"==typeof
|
131
|
+
symbol&&metadata&&\"object\"==typeof metadata,\"invalid params\")){const token=await
|
132
|
+
api.db.findOne(\"tokens\",{symbol:symbol});if(token&&api.assert(token.issuer===api.sender,\"must
|
133
|
+
be the issuer\"))try{const finalMetadata=JSON.stringify(metadata);api.assert(finalMetadata.length<=1e3,\"invalid
|
134
|
+
metadata: max length of 1000\")&&(token.metadata=finalMetadata,await api.db.update(\"tokens\",token))}catch(e){}}},actions.updatePrecision=async
|
135
|
+
payload=>{const{symbol:symbol,precision:precision,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
136
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
137
|
+
symbol)&&api.assert(precision>0&&precision<=8&&Number.isInteger(precision),\"invalid
|
138
|
+
precision\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});token&&api.assert(token.issuer===api.sender,\"must
|
139
|
+
be the issuer\")&&api.assert(precision>token.precision,\"precision can only
|
140
|
+
be increased\")&&(token.precision=precision,await api.db.update(\"tokens\",token))}},actions.transferOwnership=async
|
141
|
+
payload=>{const{symbol:symbol,to:to,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
142
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
143
|
+
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
|
144
|
+
be the issuer\")){const finalTo=to.trim();api.assert(api.isValidAccountName(finalTo),\"invalid
|
145
|
+
to\")&&(token.issuer=finalTo,await api.db.update(\"tokens\",token))}}},actions.create=async
|
146
|
+
payload=>{const{name:name,symbol:symbol,url:url,precision:precision,maxSupply:maxSupply,isSignedWithActiveKey:isSignedWithActiveKey}=payload,params=await
|
147
|
+
api.db.findOne(\"params\",{}),{tokenCreationFee:tokenCreationFee}=params,utilityTokenBalance=await
|
148
|
+
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
|
149
|
+
must have enough tokens to cover the creation fees\")&&api.assert(!0===isSignedWithActiveKey,\"you
|
150
|
+
must use a custom_json signed with your active key\")&&api.assert(name&&\"string\"==typeof
|
151
|
+
name&&symbol&&\"string\"==typeof symbol&&(void 0===url||url&&\"string\"==typeof
|
152
|
+
url)&&(precision&&\"number\"==typeof precision||0===precision)&&maxSupply&&\"string\"==typeof
|
153
|
+
maxSupply&&!api.BigNumber(maxSupply).isNaN(),\"invalid params\")&&api.assert(api.validator.isAlpha(symbol)&&api.validator.isUppercase(symbol)&&symbol.length>0&&symbol.length<=10,\"invalid
|
154
|
+
symbol: uppercase letters only, max length of 10\")&&api.assert(api.validator.isAlphanumeric(api.validator.blacklist(name,\"
|
155
|
+
\"))&&name.length>0&&name.length<=50,\"invalid name: letters, numbers, whitespaces
|
156
|
+
only, max length of 50\")&&api.assert(void 0===url||url.length<=255,\"invalid
|
157
|
+
url: max length of 255\")&&api.assert(precision>=0&&precision<=8&&Number.isInteger(precision),\"invalid
|
158
|
+
precision\")&&api.assert(api.BigNumber(maxSupply).gt(0),\"maxSupply must be
|
159
|
+
positive\")&&api.assert(api.BigNumber(maxSupply).lte(Number.MAX_SAFE_INTEGER),\"maxSupply
|
160
|
+
must be lower than \"+Number.MAX_SAFE_INTEGER)){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null===token,\"symbol
|
161
|
+
already exists\")){let metadata={url:void 0===url?\"\":url};metadata=JSON.stringify(metadata);const
|
162
|
+
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
|
163
|
+
api.db.insert(\"tokens\",newToken),api.BigNumber(tokenCreationFee).gt(0)&&await
|
164
|
+
actions.transfer({to:\"null\",symbol:\"ENG\",quantity:tokenCreationFee,isSignedWithActiveKey:isSignedWithActiveKey})}}},actions.issue=async
|
165
|
+
payload=>{const{to:to,symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
166
|
+
must use a custom_json signed with your active key\")&&api.assert(to&&\"string\"==typeof
|
167
|
+
to&&symbol&&\"string\"==typeof symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
168
|
+
params\")){const finalTo=to.trim(),token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
169
|
+
does not exist\")&&api.assert(token.issuer===api.sender,\"not allowed to issue
|
170
|
+
tokens\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol precision
|
171
|
+
mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must issue positive
|
172
|
+
quantity\")&&api.assert(api.BigNumber(token.maxSupply).minus(token.supply).gte(quantity),\"quantity
|
173
|
+
exceeds available supply\")&&api.assert(api.isValidAccountName(finalTo),\"invalid
|
174
|
+
to\")){let res=await addBalance(token.issuer,token,quantity,\"balances\");!0===res&&finalTo!==token.issuer&&await
|
175
|
+
subBalance(token.issuer,token,quantity,\"balances\")&&(res=await addBalance(finalTo,token,quantity,\"balances\"),!1===res&&await
|
176
|
+
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
|
177
|
+
api.db.update(\"tokens\",token),api.emit(\"transferFromContract\",{from:\"tokens\",to:finalTo,symbol:symbol,quantity:quantity}))}}},actions.issueToContract=async
|
178
|
+
payload=>{const{to:to,symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
179
|
+
must use a custom_json signed with your active key\")&&api.assert(to&&\"string\"==typeof
|
180
|
+
to&&symbol&&\"string\"==typeof symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
181
|
+
params\")){const finalTo=to.trim(),token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
182
|
+
does not exist\")&&api.assert(token.issuer===api.sender,\"not allowed to issue
|
183
|
+
tokens\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol precision
|
184
|
+
mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must issue positive
|
185
|
+
quantity\")&&api.assert(api.BigNumber(token.maxSupply).minus(token.supply).gte(quantity),\"quantity
|
186
|
+
exceeds available supply\")&&api.assert(finalTo.length>=3&&finalTo.length<=50,\"invalid
|
187
|
+
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
|
188
|
+
api.db.update(\"tokens\",token),api.emit(\"issueToContract\",{from:\"tokens\",to:finalTo,symbol:symbol,quantity:quantity}))}}},actions.transfer=async
|
189
|
+
payload=>{const{to:to,symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
190
|
+
must use a custom_json signed with your active key\")&&api.assert(to&&\"string\"==typeof
|
191
|
+
to&&symbol&&\"string\"==typeof symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
192
|
+
params\")){const finalTo=to.trim();if(api.assert(finalTo!==api.sender,\"cannot
|
193
|
+
transfer to self\")&&api.assert(api.isValidAccountName(finalTo),\"invalid
|
194
|
+
to\")&&api.assert(void 0===ACCOUNT_BLACKLIST[finalTo],\"not allowed to send
|
195
|
+
to \"+finalTo)){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
196
|
+
does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
197
|
+
precision mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must transfer
|
198
|
+
positive quantity\")&&await subBalance(api.sender,token,quantity,\"balances\")){return!1===await
|
199
|
+
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
|
200
|
+
api.db.update(\"tokens\",token)),api.emit(\"transfer\",{from:api.sender,to:finalTo,symbol:symbol,quantity:quantity}),!0)}}}return!1},actions.transferToContract=async
|
201
|
+
payload=>{const{from:from,to:to,symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload,finalFrom=void
|
202
|
+
0===from||\"null\"!==api.sender?api.sender:from;if(api.assert(!0===isSignedWithActiveKey||\"null\"===api.sender,\"you
|
203
|
+
must use a custom_json signed with your active key\")&&api.assert(to&&\"string\"==typeof
|
204
|
+
to&&symbol&&\"string\"==typeof symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
205
|
+
params\")){const finalTo=to.trim().toLowerCase();if(api.assert(finalTo!==finalFrom,\"cannot
|
206
|
+
transfer to self\")&&api.assert(finalTo.length>=3&&finalTo.length<=50,\"invalid
|
207
|
+
to\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
208
|
+
does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
209
|
+
precision mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must transfer
|
210
|
+
positive quantity\")&&await subBalance(finalFrom,token,quantity,\"balances\")){!1===await
|
211
|
+
addBalance(finalTo,token,quantity,\"contractsBalances\")?await addBalance(finalFrom,token,quantity,\"balances\"):(\"null\"===finalTo&&(token.circulatingSupply=calculateBalance(token.circulatingSupply,quantity,token.precision,!1),await
|
212
|
+
api.db.update(\"tokens\",token)),api.emit(\"transferToContract\",{from:finalFrom,to:finalTo,symbol:symbol,quantity:quantity}))}}}},actions.transferFromContract=async
|
213
|
+
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
|
214
|
+
to&&from&&\"string\"==typeof from&&symbol&&\"string\"==typeof symbol&&type&&types.includes(type)&&quantity&&\"string\"==typeof
|
215
|
+
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
|
216
|
+
transfer to self\")){const toValid=\"user\"===type?api.isValidAccountName(finalTo):finalTo.length>=3&&finalTo.length<=50;if(api.assert(!0===toValid,\"invalid
|
217
|
+
to\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
218
|
+
does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
219
|
+
precision mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must transfer
|
220
|
+
positive quantity\")&&await subBalance(from,token,quantity,\"contractsBalances\")){!1===await
|
221
|
+
addBalance(finalTo,token,quantity,table)?await addBalance(from,token,quantity,\"contractsBalances\"):(\"null\"===finalTo&&(token.circulatingSupply=calculateBalance(token.circulatingSupply,quantity,token.precision,!1),await
|
222
|
+
api.db.update(\"tokens\",token)),api.emit(\"transferFromContract\",{from:from,to:finalTo,symbol:symbol,quantity:quantity}))}}}}}};const
|
223
|
+
processUnstake=async unstake=>{const{account:account,symbol:symbol,quantity:quantity,quantityLeft:quantityLeft,numberTransactionsLeft:numberTransactionsLeft}=unstake,newUnstake=unstake,balance=await
|
224
|
+
api.db.findOne(\"balances\",{account:account,symbol:symbol}),token=await api.db.findOne(\"tokens\",{symbol:symbol});let
|
225
|
+
tokensToRelease=0;if(api.assert(null!==balance,\"balance does not exist\")&&(1===numberTransactionsLeft?(tokensToRelease=quantityLeft,await
|
226
|
+
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
|
227
|
+
api.db.update(\"pendingUnstakes\",newUnstake)),api.BigNumber(tokensToRelease).gt(0))){const
|
228
|
+
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
|
229
|
+
subtract\")&&(await api.db.update(\"balances\",balance),token.totalStaked=calculateBalance(token.totalStaked,tokensToRelease,token.precision,!1),await
|
230
|
+
api.db.update(\"tokens\",token),api.emit(\"unstake\",{account:account,symbol:symbol,quantity:tokensToRelease}),\"ENG\"===symbol&&await
|
231
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:account}))}};actions.checkPendingUnstakes=async()=>{if(api.assert(\"null\"===api.sender,\"not
|
232
|
+
authorized\")){const timestamp=new Date(api.steemBlockTimestamp+\".000Z\").getTime();let
|
233
|
+
pendingUnstakes=await api.db.find(\"pendingUnstakes\",{nextTransactionTimestamp:{$lte:timestamp}}),nbPendingUnstakes=pendingUnstakes.length;for(;nbPendingUnstakes>0;){for(let
|
234
|
+
index=0;index<nbPendingUnstakes;index+=1){const pendingUnstake=pendingUnstakes[index];await
|
235
|
+
processUnstake(pendingUnstake)}pendingUnstakes=await api.db.find(\"pendingUnstakes\",{nextTransactionTimestamp:{$lte:timestamp}}),nbPendingUnstakes=pendingUnstakes.length}}},actions.enableStaking=async
|
236
|
+
payload=>{const{symbol:symbol,unstakingCooldown:unstakingCooldown,numberTransactions:numberTransactions,isSignedWithActiveKey:isSignedWithActiveKey}=payload,params=await
|
237
|
+
api.db.findOne(\"params\",{}),{enableStakingFee:enableStakingFee}=params,utilityTokenBalance=await
|
238
|
+
api.db.findOne(\"balances\",{account:api.sender,symbol:\"ENG\"}),enoughFunds=utilityTokenBalance&&api.BigNumber(utilityTokenBalance.balance).gte(enableStakingFee),authorized=void
|
239
|
+
0===enableStakingFee||api.BigNumber(enableStakingFee).lte(0)||enoughFunds;if(api.assert(authorized,\"you
|
240
|
+
must have enough tokens to cover fees\")&&api.assert(!0===isSignedWithActiveKey,\"you
|
241
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
242
|
+
symbol,\"invalid symbol\")&&api.assert(unstakingCooldown&&Number.isInteger(unstakingCooldown)&&unstakingCooldown>0&&unstakingCooldown<=18250,\"unstakingCooldown
|
243
|
+
must be an integer between 1 and 18250\")&&api.assert(numberTransactions&&Number.isInteger(numberTransactions)&&numberTransactions>0&&numberTransactions<=18250,\"numberTransactions
|
244
|
+
must be an integer between 1 and 18250\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});api.assert(null!==token,\"symbol
|
245
|
+
does not exist\")&&api.assert(token.issuer===api.sender,\"must be the issuer\")&&api.assert(void
|
246
|
+
0===token.stakingEnabled||!1===token.stakingEnabled,\"staking already enabled\")&&(token.stakingEnabled=!0,token.totalStaked=\"0\",token.unstakingCooldown=unstakingCooldown,token.numberTransactions=numberTransactions,await
|
247
|
+
api.db.update(\"tokens\",token),api.BigNumber(enableStakingFee).gt(0)&&await
|
248
|
+
actions.transfer({to:\"null\",symbol:\"ENG\",quantity:enableStakingFee,isSignedWithActiveKey:isSignedWithActiveKey}))}},actions.stake=async
|
249
|
+
payload=>{const{symbol:symbol,quantity:quantity,to:to,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
250
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
251
|
+
symbol&&to&&\"string\"==typeof to&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
252
|
+
params\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol}),finalTo=to.trim();if(api.assert(api.isValidAccountName(finalTo),\"invalid
|
253
|
+
to\")&&api.assert(null!==token,\"symbol does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
254
|
+
precision mismatch\")&&api.assert(!0===token.stakingEnabled,\"staking not
|
255
|
+
enabled\")&&api.assert(api.BigNumber(quantity).gt(0),\"must stake positive
|
256
|
+
quantity\")&&await subBalance(api.sender,token,quantity,\"balances\")){!1===await
|
257
|
+
addStake(finalTo,token,quantity)?await addBalance(api.sender,token,quantity,\"balances\"):(api.emit(\"stake\",{account:finalTo,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&await
|
258
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:api.sender}))}}},actions.stakeFromContract=async
|
259
|
+
payload=>{const{symbol:symbol,quantity:quantity,to:to,callingContractInfo:callingContractInfo}=payload;if(callingContractInfo&&api.assert(symbol&&\"string\"==typeof
|
260
|
+
symbol&&to&&\"string\"==typeof to&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
261
|
+
params\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol}),finalTo=to.trim();if(api.assert(api.isValidAccountName(finalTo),\"invalid
|
262
|
+
to\")&&api.assert(null!==token,\"symbol does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
263
|
+
precision mismatch\")&&api.assert(!0===token.stakingEnabled,\"staking not
|
264
|
+
enabled\")&&api.assert(api.BigNumber(quantity).gt(0),\"must stake positive
|
265
|
+
quantity\")&&await subBalance(callingContractInfo.name,token,quantity,\"contractsBalances\")){!1===await
|
266
|
+
addStake(finalTo,token,quantity)?await addBalance(callingContractInfo.name,token,quantity,\"balances\"):(api.emit(\"stakeFromContract\",{account:finalTo,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&await
|
267
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:finalTo}))}}};const
|
268
|
+
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
|
269
|
+
api.db.insert(\"pendingUnstakes\",unstake)};actions.unstake=async payload=>{const{symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
270
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
271
|
+
symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
272
|
+
params\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});api.assert(null!==token,\"symbol
|
273
|
+
does not exist\")&&api.assert(!0===token.stakingEnabled,\"staking not enabled\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
274
|
+
precision mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must unstake
|
275
|
+
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
|
276
|
+
processCancelUnstake=async unstake=>{const{account:account,symbol:symbol,quantityLeft:quantityLeft}=unstake,balance=await
|
277
|
+
api.db.findOne(\"balances\",{account:account,symbol:symbol}),token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==balance,\"balance
|
278
|
+
does not exist\")&&api.assert(api.BigNumber(balance.pendingUnstake).gte(quantityLeft),\"overdrawn
|
279
|
+
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
|
280
|
+
subtract\"))return await api.db.update(\"balances\",balance),api.emit(\"unstake\",{account:account,symbol:symbol,quantity:quantityLeft}),!0}return!1};actions.cancelUnstake=async
|
281
|
+
payload=>{const{txID:txID,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
282
|
+
must use a custom_json signed with your active key\")&&api.assert(txID&&\"string\"==typeof
|
283
|
+
txID,\"invalid params\")){const unstake=await api.db.findOne(\"pendingUnstakes\",{account:api.sender,txID:txID});api.assert(unstake,\"unstake
|
284
|
+
does not exist\")&&await processCancelUnstake(unstake)&&await api.db.remove(\"pendingUnstakes\",unstake)}},actions.enableDelegation=async
|
285
|
+
payload=>{const{symbol:symbol,undelegationCooldown:undelegationCooldown,isSignedWithActiveKey:isSignedWithActiveKey}=payload,params=await
|
286
|
+
api.db.findOne(\"params\",{}),{enableDelegationFee:enableDelegationFee}=params,utilityTokenBalance=await
|
287
|
+
api.db.findOne(\"balances\",{account:api.sender,symbol:\"ENG\"}),enoughFunds=utilityTokenBalance&&api.BigNumber(utilityTokenBalance.balance).gte(enableDelegationFee),authorized=void
|
288
|
+
0===enableDelegationFee||api.BigNumber(enableDelegationFee).lte(0)||enoughFunds;if(api.assert(authorized,\"you
|
289
|
+
must have enough tokens to cover fees\")&&api.assert(!0===isSignedWithActiveKey,\"you
|
290
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
291
|
+
symbol,\"invalid symbol\")&&api.assert(undelegationCooldown&&Number.isInteger(undelegationCooldown)&&undelegationCooldown>0&&undelegationCooldown<=18250,\"undelegationCooldown
|
292
|
+
must be an integer between 1 and 18250\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});api.assert(null!==token,\"symbol
|
293
|
+
does not exist\")&&api.assert(token.issuer===api.sender,\"must be the issuer\")&&api.assert(!0===token.stakingEnabled,\"staking
|
294
|
+
not enabled\")&&api.assert(void 0===token.delegationEnabled||!1===token.delegationEnabled,\"delegation
|
295
|
+
already enabled\")&&(token.delegationEnabled=!0,token.undelegationCooldown=undelegationCooldown,await
|
296
|
+
api.db.update(\"tokens\",token),api.BigNumber(enableDelegationFee).gt(0)&&await
|
297
|
+
actions.transfer({to:\"null\",symbol:\"ENG\",quantity:enableDelegationFee,isSignedWithActiveKey:isSignedWithActiveKey}))}},actions.delegate=async
|
298
|
+
payload=>{const{symbol:symbol,quantity:quantity,to:to,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
299
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
300
|
+
symbol&&to&&\"string\"==typeof to&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
301
|
+
params\")){const finalTo=to.trim();if(api.assert(api.isValidAccountName(finalTo),\"invalid
|
302
|
+
to\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
303
|
+
does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
304
|
+
precision mismatch\")&&api.assert(!0===token.delegationEnabled,\"delegation
|
305
|
+
not enabled\")&&api.assert(finalTo!==api.sender,\"cannot delegate to yourself\")&&api.assert(api.BigNumber(quantity).gt(0),\"must
|
306
|
+
delegate positive quantity\")){const balanceFrom=await api.db.findOne(\"balances\",{account:api.sender,symbol:symbol});if(api.assert(null!==balanceFrom,\"balanceFrom
|
307
|
+
does not exist\")&&api.assert(api.BigNumber(balanceFrom.stake).gte(quantity),\"overdrawn
|
308
|
+
stake\")){void 0===balanceFrom.stake?(balanceFrom.stake=\"0\",balanceFrom.pendingUnstake=\"0\",balanceFrom.delegationsIn=\"0\",balanceFrom.delegationsOut=\"0\",balanceFrom.pendingUndelegations=\"0\"):void
|
309
|
+
0===balanceFrom.delegationsIn&&(balanceFrom.delegationsIn=\"0\",balanceFrom.delegationsOut=\"0\",balanceFrom.pendingUndelegations=\"0\",balanceFrom.delegatedStake&&(delete
|
310
|
+
balanceFrom.delegatedStake,delete balanceFrom.receivedStake));let balanceTo=await
|
311
|
+
api.db.findOne(\"balances\",{account:finalTo,symbol:symbol});null===balanceTo?(balanceTo=balanceTemplate,balanceTo.account=finalTo,balanceTo.symbol=symbol,balanceTo=await
|
312
|
+
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
|
313
|
+
0===balanceTo.delegationsIn&&(balanceTo.delegationsIn=\"0\",balanceTo.delegationsOut=\"0\",balanceTo.pendingUndelegations=\"0\",balanceTo.delegatedStake&&(delete
|
314
|
+
balanceTo.delegatedStake,delete balanceTo.receivedStake));let delegation=await
|
315
|
+
api.db.findOne(\"delegations\",{to:finalTo,from:api.sender,symbol:symbol});const
|
316
|
+
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
|
317
|
+
api.db.update(\"balances\",balanceFrom),balanceTo.delegationsIn=calculateBalance(balanceTo.delegationsIn,quantity,token.precision,!0),await
|
318
|
+
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
|
319
|
+
api.db.insert(\"delegations\",delegation),api.emit(\"delegate\",{to:finalTo,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&(await
|
320
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:api.sender}),await
|
321
|
+
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
|
322
|
+
api.db.update(\"balances\",balanceFrom),balanceTo.delegationsIn=calculateBalance(balanceTo.delegationsIn,quantity,token.precision,!0),await
|
323
|
+
api.db.update(\"balances\",balanceTo),delegation.quantity=calculateBalance(delegation.quantity,quantity,token.precision,!0),delegation.updated=timestamp,await
|
324
|
+
api.db.update(\"delegations\",delegation),api.emit(\"delegate\",{to:finalTo,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&(await
|
325
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:api.sender}),await
|
326
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:finalTo})))}}}}},actions.undelegate=async
|
327
|
+
payload=>{const{symbol:symbol,quantity:quantity,from:from,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
|
328
|
+
must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
|
329
|
+
symbol&&from&&\"string\"==typeof from&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
|
330
|
+
params\")){const finalFrom=from.trim();if(api.assert(finalFrom.length>=3&&finalFrom.length<=16,\"invalid
|
331
|
+
from\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
|
332
|
+
does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
|
333
|
+
precision mismatch\")&&api.assert(!0===token.delegationEnabled,\"delegation
|
334
|
+
not enabled\")&&api.assert(finalFrom!==api.sender,\"cannot undelegate from
|
335
|
+
yourself\")&&api.assert(api.BigNumber(quantity).gt(0),\"must undelegate positive
|
336
|
+
quantity\")){const balanceTo=await api.db.findOne(\"balances\",{account:api.sender,symbol:symbol});if(api.assert(null!==balanceTo,\"balanceTo
|
337
|
+
does not exist\")&&api.assert(api.BigNumber(balanceTo.delegationsOut).gte(quantity),\"overdrawn
|
338
|
+
delegation\")){const balanceFrom=await api.db.findOne(\"balances\",{account:finalFrom,symbol:symbol});if(api.assert(null!==balanceFrom,\"balanceFrom
|
339
|
+
does not exist\")){const delegation=await api.db.findOne(\"delegations\",{to:finalFrom,from:api.sender,symbol:symbol});if(api.assert(null!==delegation,\"delegation
|
340
|
+
does not exist\")&&api.assert(api.BigNumber(delegation.quantity).gte(quantity),\"overdrawn
|
341
|
+
delegation\")){balanceTo.pendingUndelegations=calculateBalance(balanceFrom.pendingUndelegations,quantity,token.precision,!0),balanceTo.delegationsOut=calculateBalance(balanceTo.delegationsOut,quantity,token.precision,!1),await
|
342
|
+
api.db.update(\"balances\",balanceTo),balanceFrom.delegationsIn=calculateBalance(balanceFrom.delegationsIn,quantity,token.precision,!1),await
|
343
|
+
api.db.update(\"balances\",balanceFrom),delegation.quantity=calculateBalance(delegation.quantity,quantity,token.precision,!1),api.BigNumber(delegation.quantity).gt(0)?await
|
344
|
+
api.db.update(\"delegations\",delegation):await api.db.remove(\"delegations\",delegation);const
|
345
|
+
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
|
346
|
+
api.db.insert(\"pendingUndelegations\",undelegation),api.emit(\"undelegateStart\",{from:finalFrom,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&await
|
347
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:finalFrom})}}}}}}};const
|
348
|
+
processUndelegation=async undelegation=>{const{account:account,symbol:symbol,quantity:quantity}=undelegation,balance=await
|
349
|
+
api.db.findOne(\"balances\",{account:account,symbol:symbol}),token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==balance,\"balance
|
350
|
+
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
|
351
|
+
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
|
352
|
+
api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:account}))}};actions.checkPendingUndelegations=async()=>{if(api.assert(\"null\"===api.sender,\"not
|
353
|
+
authorized\")){const timestamp=new Date(api.steemBlockTimestamp+\".000Z\").getTime();let
|
354
|
+
pendingUndelegations=await api.db.find(\"pendingUndelegations\",{completeTimestamp:{$lte:timestamp}}),nbPendingUndelegations=pendingUndelegations.length;for(;nbPendingUndelegations>0;){for(let
|
355
|
+
index=0;index<nbPendingUndelegations;index+=1){const pendingUndelegation=pendingUndelegations[index];await
|
356
|
+
processUndelegation(pendingUndelegation)}pendingUndelegations=await api.db.find(\"pendingUndelegations\",{completeTimestamp:{$lte:timestamp}}),nbPendingUndelegations=pendingUndelegations.length}}};\n \n const
|
357
|
+
execute = async function () {\n try {\n if (api.action
|
358
|
+
&& typeof api.action === ''string'' && typeof actions[api.action] === ''function'')
|
359
|
+
{\n if (api.action !== ''createSSC'') {\n actions.createSSC
|
360
|
+
= null;\n }\n await actions[api.action](api.payload);\n done(null);\n }
|
361
|
+
else {\n done(''invalid action'');\n }\n }
|
362
|
+
catch (error) {\n done(error);\n }\n }\n \n execute();\n }\n\n wrapper();\n ","codeHash":"d3ab1afa743f5322eb1b5da7ada99c43f7d26f47cfaab98acb9322c929b23ea6","tables":{"tokens_tokens":{"size":0,"hash":"251584a3308868ff468c0c9e47bdd8cbdf74a5e2d5e220e80f3f65fb05dc7f1c","nbIndexes":1},"tokens_balances":{"size":0,"hash":"884388cc2b9215cfacfcbb1ad81568c7676a51bf2138f1fd09cba58002f4bb1c","nbIndexes":1},"tokens_contractsBalances":{"size":0,"hash":"e70b037936001ff7a4f90253d76e39679ce0f800e58801e1ce267361fafb2f74","nbIndexes":1},"tokens_params":{"size":0,"hash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","nbIndexes":0},"tokens_pendingUnstakes":{"size":0,"hash":"2c5f6685d85dc68d4d7c02d7266b620b97990583d90900e1cef93da9070b4f5b","nbIndexes":2},"tokens_delegations":{"size":0,"hash":"3897f12cf8c4bec58b5ea4b78de879dda0fd978de12324876b4cb38b112b2449","nbIndexes":2},"tokens_pendingUndelegations":{"size":0,"hash":"0fbc3ab4616bd76948c846454383e2d0f8fd5da012134193672685cc23e6131a","nbIndexes":2}},"version":17}}'
|
363
|
+
recorded_at: Sat, 07 Nov 2020 20:13:32 GMT
|
364
|
+
recorded_with: VCR 6.0.0
|