radiator 0.4.8 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/radiator/api.rb +8 -8
  4. data/lib/radiator/ssc/base_steem_smart_contract_rpc.rb +1 -1
  5. data/lib/radiator/ssc/blockchain.rb +1 -1
  6. data/lib/radiator/ssc/contracts.rb +1 -1
  7. data/lib/radiator/ssc/stream.rb +1 -1
  8. data/lib/radiator/version.rb +1 -1
  9. data/radiator.gemspec +3 -3
  10. data/test/fixtures/vcr_cassettes/account_by_key_api_all_methods.yml +207 -1
  11. data/test/fixtures/vcr_cassettes/api_all_methods.yml +331 -1
  12. data/test/fixtures/vcr_cassettes/base_per_debt.yml +855 -1
  13. data/test/fixtures/vcr_cassettes/base_per_mvest.yml +651 -1
  14. data/test/fixtures/vcr_cassettes/block_time.yml +733 -1
  15. data/test/fixtures/vcr_cassettes/broadcast_transaction.yml +108 -1
  16. data/test/fixtures/vcr_cassettes/condenser_all_all_methods.yml +166 -1
  17. data/test/fixtures/vcr_cassettes/expiration_initialize.yml +1162 -1
  18. data/test/fixtures/vcr_cassettes/find_account.yml +633 -1
  19. data/test/fixtures/vcr_cassettes/find_block.yml +628 -1
  20. data/test/fixtures/vcr_cassettes/find_comment.yml +1967 -1
  21. data/test/fixtures/vcr_cassettes/get_account_count.yml +53 -1
  22. data/test/fixtures/vcr_cassettes/get_account_references.yml +111 -1
  23. data/test/fixtures/vcr_cassettes/get_accounts.yml +62 -1
  24. data/test/fixtures/vcr_cassettes/get_accounts_no_argument.yml +111 -1
  25. data/test/fixtures/vcr_cassettes/get_dynamic_global_properties.yml +59 -1
  26. data/test/fixtures/vcr_cassettes/get_feed_history.yml +191 -1
  27. data/test/fixtures/vcr_cassettes/get_hardfork_version.yml +53 -1
  28. data/test/fixtures/vcr_cassettes/get_key_references.yml +211 -1
  29. data/test/fixtures/vcr_cassettes/get_market_history.yml +209 -1
  30. data/test/fixtures/vcr_cassettes/get_market_history_buckets.yml +209 -1
  31. data/test/fixtures/vcr_cassettes/get_order_book.yml +209 -1
  32. data/test/fixtures/vcr_cassettes/get_recent_trades.yml +209 -1
  33. data/test/fixtures/vcr_cassettes/get_ticker.yml +105 -1
  34. data/test/fixtures/vcr_cassettes/get_trade_history.yml +209 -1
  35. data/test/fixtures/vcr_cassettes/get_vesting_delegations.yml +105 -1
  36. data/test/fixtures/vcr_cassettes/get_volume.yml +213 -1
  37. data/test/fixtures/vcr_cassettes/get_witness_by_account.yml +53 -1
  38. data/test/fixtures/vcr_cassettes/look_up_witnesses.yml +53 -1
  39. data/test/fixtures/vcr_cassettes/market_history_api_all_methods.yml +1461 -1
  40. data/test/fixtures/vcr_cassettes/network_broadcast_api_all_methods.yml +217 -1
  41. data/test/fixtures/vcr_cassettes/properties.yml +633 -1
  42. data/test/fixtures/vcr_cassettes/recover_transaction.yml +111 -1
  43. data/test/fixtures/vcr_cassettes/ssc_blockchain_block_info.yml +90 -3
  44. data/test/fixtures/vcr_cassettes/ssc_blockchain_block_info_invalid.yml +88 -3
  45. data/test/fixtures/vcr_cassettes/ssc_blockchain_latest_block_info.yml +89 -3
  46. data/test/fixtures/vcr_cassettes/ssc_blockchain_transaction_info.yml +82 -3
  47. data/test/fixtures/vcr_cassettes/ssc_contracts_contract.yml +364 -3
  48. data/test/fixtures/vcr_cassettes/ssc_contracts_find.yml +81 -3
  49. data/test/fixtures/vcr_cassettes/ssc_contracts_find_one.yml +87 -3
  50. data/test/fixtures/vcr_cassettes/stream_jsonrpc.yml +2167 -1
  51. data/test/fixtures/vcr_cassettes/transaction_expiration_initialize_nil.yml +1229 -1
  52. data/test/fixtures/vcr_cassettes/transaction_jsonrpc.yml +2131 -1
  53. data/test/fixtures/vcr_cassettes/unknown_chain_id.yml +1203 -1
  54. data/test/fixtures/vcr_cassettes/valid_chains.yml +1157 -1
  55. metadata +42 -42
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: https://api.steem-engine.com/rpc/contracts
5
+ uri: https://api.steem-engine.net/rpc/contracts
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"method":"find","params":{"contract":"tokens","table":"transfers","query":{"symbol":""},"limit":0},"jsonrpc":"2.0","id":2}'
@@ -44,7 +44,7 @@ http_interactions:
44
44
  recorded_at: Sat, 07 Nov 2020 20:13:32 GMT
45
45
  - request:
46
46
  method: post
47
- uri: https://api.steem-engine.com/rpc/contracts
47
+ uri: https://api.steem-engine.net/rpc/contracts
48
48
  body:
49
49
  encoding: UTF-8
50
50
  string: '{"method":"getContract","params":{"name":"tokens"},"jsonrpc":"2.0","id":1}'
@@ -361,4 +361,365 @@ http_interactions:
361
361
  else {\n done(''invalid action'');\n }\n }
362
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
363
  recorded_at: Sat, 07 Nov 2020 20:13:32 GMT
364
- recorded_with: VCR 6.0.0
364
+ - request:
365
+ method: post
366
+ uri: https://api.steem-engine.net/rpc/contracts
367
+ body:
368
+ encoding: UTF-8
369
+ string: '{"method":"find","params":{"contract":"tokens","table":"transfers","query":{"symbol":""},"limit":0},"jsonrpc":"2.0","id":2}'
370
+ headers:
371
+ Content-Type:
372
+ - application/json
373
+ User-Agent:
374
+ - radiator/0.4.9
375
+ Accept-Encoding:
376
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
377
+ Accept:
378
+ - "*/*"
379
+ Connection:
380
+ - keep-alive
381
+ Keep-Alive:
382
+ - '30'
383
+ response:
384
+ status:
385
+ code: 200
386
+ message: OK
387
+ headers:
388
+ Server:
389
+ - nginx/1.10.3 (Ubuntu)
390
+ Date:
391
+ - Sat, 30 Jul 2022 23:22:57 GMT
392
+ Content-Type:
393
+ - application/json; charset=utf-8
394
+ Content-Length:
395
+ - '38'
396
+ Connection:
397
+ - keep-alive
398
+ X-Powered-By:
399
+ - Express
400
+ Access-Control-Allow-Origin:
401
+ - "*"
402
+ body:
403
+ encoding: UTF-8
404
+ string: '{"jsonrpc":"2.0","id":2,"result":null}'
405
+ recorded_at: Sat, 30 Jul 2022 23:22:57 GMT
406
+ - request:
407
+ method: post
408
+ uri: https://api.steem-engine.net/rpc/contracts
409
+ body:
410
+ encoding: UTF-8
411
+ string: '{"method":"getContract","params":{"name":"tokens"},"jsonrpc":"2.0","id":1}'
412
+ headers:
413
+ Content-Type:
414
+ - application/json
415
+ User-Agent:
416
+ - radiator/0.4.9
417
+ Accept-Encoding:
418
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
419
+ Accept:
420
+ - "*/*"
421
+ Connection:
422
+ - keep-alive
423
+ Keep-Alive:
424
+ - '30'
425
+ response:
426
+ status:
427
+ code: 200
428
+ message: OK
429
+ headers:
430
+ Server:
431
+ - nginx/1.10.3 (Ubuntu)
432
+ Date:
433
+ - Sat, 30 Jul 2022 23:22:57 GMT
434
+ Content-Type:
435
+ - application/json; charset=utf-8
436
+ Transfer-Encoding:
437
+ - chunked
438
+ Connection:
439
+ - keep-alive
440
+ Vary:
441
+ - Accept-Encoding
442
+ X-Powered-By:
443
+ - Express
444
+ Access-Control-Allow-Origin:
445
+ - "*"
446
+ body:
447
+ encoding: ASCII-8BIT
448
+ string: '{"jsonrpc":"2.0","id":1,"result":{"_id":"tokens","owner":"steemsc","code":"\n function
449
+ wrapper () {\n RegExp.prototype.constructor = function () { };\n RegExp.prototype.exec
450
+ = function () { };\n RegExp.prototype.test = function () { };\n \n let
451
+ 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
452
+ tableExists=await api.db.tableExists(\"tokens\");if(!1===tableExists){await
453
+ api.db.createTable(\"tokens\",[\"symbol\"]),await api.db.createTable(\"balances\",[\"account\"]),await
454
+ api.db.createTable(\"contractsBalances\",[\"account\"]),await api.db.createTable(\"params\");const
455
+ params={tokenCreationFee:\"0\"};await api.db.insert(\"params\",params)}else{const
456
+ params=await api.db.findOne(\"params\",{});params.enableDelegationFee=\"1000\",params.enableStakingFee=\"1000\",await
457
+ api.db.update(\"params\",params)}tableExists=await api.db.tableExists(\"pendingUnstakes\"),!1===tableExists&&await
458
+ api.db.createTable(\"pendingUnstakes\",[\"account\",\"unstakeCompleteTimestamp\"]),tableExists=await
459
+ api.db.tableExists(\"delegations\"),!1===tableExists&&(await api.db.createTable(\"delegations\",[\"from\",\"to\"]),await
460
+ api.db.createTable(\"pendingUndelegations\",[\"account\",\"completeTimestamp\"]));let
461
+ token=await api.db.findOne(\"tokens\",{symbol:\"STEEMP\"});token&&token.precision<8&&(token.precision=8,await
462
+ api.db.update(\"tokens\",token)),token=await api.db.findOne(\"tokens\",{symbol:\"ENG\"}),void
463
+ 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
464
+ 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
465
+ balance=await api.db.findOne(\"balances\",{account:account,symbol:token.symbol});null===balance&&(balance=balanceTemplate,balance.account=account,balance.symbol=token.symbol,balance=await
466
+ api.db.insert(\"balances\",balance)),void 0===balance.stake&&(balance.stake=\"0\",balance.pendingUnstake=\"0\");const
467
+ originalStake=balance.stake;return balance.stake=calculateBalance(balance.stake,quantity,token.precision,!0),!!api.assert(api.BigNumber(balance.stake).gt(originalStake),\"cannot
468
+ add\")&&(await api.db.update(\"balances\",balance),void 0===token.totalStaked&&(token.totalStaked=\"0\"),token.totalStaked=calculateBalance(token.totalStaked,quantity,token.precision,!0),await
469
+ api.db.update(\"tokens\",token),!0)},subStake=async(account,token,quantity)=>{const
470
+ balance=await api.db.findOne(\"balances\",{account:account,symbol:token.symbol});if(api.assert(null!==balance,\"balance
471
+ does not exist\")&&api.assert(api.BigNumber(balance.stake).gte(quantity),\"overdrawn
472
+ 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
473
+ subtract\"))return await api.db.update(\"balances\",balance),!0}return!1},subBalance=async(account,token,quantity,table)=>{const
474
+ balance=await api.db.findOne(table,{account:account,symbol:token.symbol});if(api.assert(null!==balance,\"balance
475
+ does not exist\")&&api.assert(api.BigNumber(balance.balance).gte(quantity),\"overdrawn
476
+ balance\")){const originalBalance=balance.balance;if(balance.balance=calculateBalance(balance.balance,quantity,token.precision,!1),api.assert(api.BigNumber(balance.balance).lt(originalBalance),\"cannot
477
+ subtract\"))return await api.db.update(table,balance),!0}return!1},addBalance=async(account,token,quantity,table)=>{let
478
+ balance=await api.db.findOne(table,{account:account,symbol:token.symbol});if(null===balance)return
479
+ balance=balanceTemplate,balance.account=account,balance.symbol=token.symbol,balance.balance=quantity,await
480
+ api.db.insert(table,balance),!0;const originalBalance=balance.balance;return
481
+ balance.balance=calculateBalance(balance.balance,quantity,token.precision,!0),!!api.assert(api.BigNumber(balance.balance).gt(originalBalance),\"cannot
482
+ add\")&&(await api.db.update(table,balance),!0)};actions.updateParams=async
483
+ payload=>{if(api.sender!==api.owner)return;const{tokenCreationFee:tokenCreationFee}=payload,params=await
484
+ api.db.findOne(\"params\",{});params.tokenCreationFee=tokenCreationFee,await
485
+ api.db.update(\"params\",params)},actions.updateUrl=async payload=>{const{url:url,symbol:symbol}=payload;if(api.assert(symbol&&\"string\"==typeof
486
+ symbol&&url&&\"string\"==typeof url,\"invalid params\")&&api.assert(url.length<=255,\"invalid
487
+ url: max length of 255\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(token&&api.assert(token.issuer===api.sender,\"must
488
+ be the issuer\"))try{const metadata=JSON.parse(token.metadata);api.assert(metadata&&metadata.url,\"an
489
+ error occured when trying to update the url\")&&(metadata.url=url,token.metadata=JSON.stringify(metadata),await
490
+ api.db.update(\"tokens\",token))}catch(e){}}},actions.updateMetadata=async
491
+ payload=>{const{metadata:metadata,symbol:symbol}=payload;if(api.assert(symbol&&\"string\"==typeof
492
+ symbol&&metadata&&\"object\"==typeof metadata,\"invalid params\")){const token=await
493
+ api.db.findOne(\"tokens\",{symbol:symbol});if(token&&api.assert(token.issuer===api.sender,\"must
494
+ be the issuer\"))try{const finalMetadata=JSON.stringify(metadata);api.assert(finalMetadata.length<=1e3,\"invalid
495
+ metadata: max length of 1000\")&&(token.metadata=finalMetadata,await api.db.update(\"tokens\",token))}catch(e){}}},actions.updatePrecision=async
496
+ payload=>{const{symbol:symbol,precision:precision,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
497
+ must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
498
+ symbol)&&api.assert(precision>0&&precision<=8&&Number.isInteger(precision),\"invalid
499
+ precision\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});token&&api.assert(token.issuer===api.sender,\"must
500
+ be the issuer\")&&api.assert(precision>token.precision,\"precision can only
501
+ be increased\")&&(token.precision=precision,await api.db.update(\"tokens\",token))}},actions.transferOwnership=async
502
+ payload=>{const{symbol:symbol,to:to,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
503
+ must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
504
+ 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
505
+ be the issuer\")){const finalTo=to.trim();api.assert(api.isValidAccountName(finalTo),\"invalid
506
+ to\")&&(token.issuer=finalTo,await api.db.update(\"tokens\",token))}}},actions.create=async
507
+ payload=>{const{name:name,symbol:symbol,url:url,precision:precision,maxSupply:maxSupply,isSignedWithActiveKey:isSignedWithActiveKey}=payload,params=await
508
+ api.db.findOne(\"params\",{}),{tokenCreationFee:tokenCreationFee}=params,utilityTokenBalance=await
509
+ 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
510
+ must have enough tokens to cover the creation fees\")&&api.assert(!0===isSignedWithActiveKey,\"you
511
+ must use a custom_json signed with your active key\")&&api.assert(name&&\"string\"==typeof
512
+ name&&symbol&&\"string\"==typeof symbol&&(void 0===url||url&&\"string\"==typeof
513
+ url)&&(precision&&\"number\"==typeof precision||0===precision)&&maxSupply&&\"string\"==typeof
514
+ maxSupply&&!api.BigNumber(maxSupply).isNaN(),\"invalid params\")&&api.assert(api.validator.isAlpha(symbol)&&api.validator.isUppercase(symbol)&&symbol.length>0&&symbol.length<=10,\"invalid
515
+ symbol: uppercase letters only, max length of 10\")&&api.assert(api.validator.isAlphanumeric(api.validator.blacklist(name,\"
516
+ \"))&&name.length>0&&name.length<=50,\"invalid name: letters, numbers, whitespaces
517
+ only, max length of 50\")&&api.assert(void 0===url||url.length<=255,\"invalid
518
+ url: max length of 255\")&&api.assert(precision>=0&&precision<=8&&Number.isInteger(precision),\"invalid
519
+ precision\")&&api.assert(api.BigNumber(maxSupply).gt(0),\"maxSupply must be
520
+ positive\")&&api.assert(api.BigNumber(maxSupply).lte(Number.MAX_SAFE_INTEGER),\"maxSupply
521
+ must be lower than \"+Number.MAX_SAFE_INTEGER)){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null===token,\"symbol
522
+ already exists\")){let metadata={url:void 0===url?\"\":url};metadata=JSON.stringify(metadata);const
523
+ 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
524
+ api.db.insert(\"tokens\",newToken),api.BigNumber(tokenCreationFee).gt(0)&&await
525
+ actions.transfer({to:\"null\",symbol:\"ENG\",quantity:tokenCreationFee,isSignedWithActiveKey:isSignedWithActiveKey})}}},actions.issue=async
526
+ payload=>{const{to:to,symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
527
+ must use a custom_json signed with your active key\")&&api.assert(to&&\"string\"==typeof
528
+ to&&symbol&&\"string\"==typeof symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
529
+ params\")){const finalTo=to.trim(),token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
530
+ does not exist\")&&api.assert(token.issuer===api.sender,\"not allowed to issue
531
+ tokens\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol precision
532
+ mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must issue positive
533
+ quantity\")&&api.assert(api.BigNumber(token.maxSupply).minus(token.supply).gte(quantity),\"quantity
534
+ exceeds available supply\")&&api.assert(api.isValidAccountName(finalTo),\"invalid
535
+ to\")){let res=await addBalance(token.issuer,token,quantity,\"balances\");!0===res&&finalTo!==token.issuer&&await
536
+ subBalance(token.issuer,token,quantity,\"balances\")&&(res=await addBalance(finalTo,token,quantity,\"balances\"),!1===res&&await
537
+ 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
538
+ api.db.update(\"tokens\",token),api.emit(\"transferFromContract\",{from:\"tokens\",to:finalTo,symbol:symbol,quantity:quantity}))}}},actions.issueToContract=async
539
+ payload=>{const{to:to,symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
540
+ must use a custom_json signed with your active key\")&&api.assert(to&&\"string\"==typeof
541
+ to&&symbol&&\"string\"==typeof symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
542
+ params\")){const finalTo=to.trim(),token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
543
+ does not exist\")&&api.assert(token.issuer===api.sender,\"not allowed to issue
544
+ tokens\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol precision
545
+ mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must issue positive
546
+ quantity\")&&api.assert(api.BigNumber(token.maxSupply).minus(token.supply).gte(quantity),\"quantity
547
+ exceeds available supply\")&&api.assert(finalTo.length>=3&&finalTo.length<=50,\"invalid
548
+ 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
549
+ api.db.update(\"tokens\",token),api.emit(\"issueToContract\",{from:\"tokens\",to:finalTo,symbol:symbol,quantity:quantity}))}}},actions.transfer=async
550
+ payload=>{const{to:to,symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
551
+ must use a custom_json signed with your active key\")&&api.assert(to&&\"string\"==typeof
552
+ to&&symbol&&\"string\"==typeof symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
553
+ params\")){const finalTo=to.trim();if(api.assert(finalTo!==api.sender,\"cannot
554
+ transfer to self\")&&api.assert(api.isValidAccountName(finalTo),\"invalid
555
+ to\")&&api.assert(void 0===ACCOUNT_BLACKLIST[finalTo],\"not allowed to send
556
+ to \"+finalTo)){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
557
+ does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
558
+ precision mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must transfer
559
+ positive quantity\")&&await subBalance(api.sender,token,quantity,\"balances\")){return!1===await
560
+ 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
561
+ api.db.update(\"tokens\",token)),api.emit(\"transfer\",{from:api.sender,to:finalTo,symbol:symbol,quantity:quantity}),!0)}}}return!1},actions.transferToContract=async
562
+ payload=>{const{from:from,to:to,symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload,finalFrom=void
563
+ 0===from||\"null\"!==api.sender?api.sender:from;if(api.assert(!0===isSignedWithActiveKey||\"null\"===api.sender,\"you
564
+ must use a custom_json signed with your active key\")&&api.assert(to&&\"string\"==typeof
565
+ to&&symbol&&\"string\"==typeof symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
566
+ params\")){const finalTo=to.trim().toLowerCase();if(api.assert(finalTo!==finalFrom,\"cannot
567
+ transfer to self\")&&api.assert(finalTo.length>=3&&finalTo.length<=50,\"invalid
568
+ to\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
569
+ does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
570
+ precision mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must transfer
571
+ positive quantity\")&&await subBalance(finalFrom,token,quantity,\"balances\")){!1===await
572
+ addBalance(finalTo,token,quantity,\"contractsBalances\")?await addBalance(finalFrom,token,quantity,\"balances\"):(\"null\"===finalTo&&(token.circulatingSupply=calculateBalance(token.circulatingSupply,quantity,token.precision,!1),await
573
+ api.db.update(\"tokens\",token)),api.emit(\"transferToContract\",{from:finalFrom,to:finalTo,symbol:symbol,quantity:quantity}))}}}},actions.transferFromContract=async
574
+ 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
575
+ to&&from&&\"string\"==typeof from&&symbol&&\"string\"==typeof symbol&&type&&types.includes(type)&&quantity&&\"string\"==typeof
576
+ 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
577
+ transfer to self\")){const toValid=\"user\"===type?api.isValidAccountName(finalTo):finalTo.length>=3&&finalTo.length<=50;if(api.assert(!0===toValid,\"invalid
578
+ to\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
579
+ does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
580
+ precision mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must transfer
581
+ positive quantity\")&&await subBalance(from,token,quantity,\"contractsBalances\")){!1===await
582
+ addBalance(finalTo,token,quantity,table)?await addBalance(from,token,quantity,\"contractsBalances\"):(\"null\"===finalTo&&(token.circulatingSupply=calculateBalance(token.circulatingSupply,quantity,token.precision,!1),await
583
+ api.db.update(\"tokens\",token)),api.emit(\"transferFromContract\",{from:from,to:finalTo,symbol:symbol,quantity:quantity}))}}}}}};const
584
+ processUnstake=async unstake=>{const{account:account,symbol:symbol,quantity:quantity,quantityLeft:quantityLeft,numberTransactionsLeft:numberTransactionsLeft}=unstake,newUnstake=unstake,balance=await
585
+ api.db.findOne(\"balances\",{account:account,symbol:symbol}),token=await api.db.findOne(\"tokens\",{symbol:symbol});let
586
+ tokensToRelease=0;if(api.assert(null!==balance,\"balance does not exist\")&&(1===numberTransactionsLeft?(tokensToRelease=quantityLeft,await
587
+ 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
588
+ api.db.update(\"pendingUnstakes\",newUnstake)),api.BigNumber(tokensToRelease).gt(0))){const
589
+ 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
590
+ subtract\")&&(await api.db.update(\"balances\",balance),token.totalStaked=calculateBalance(token.totalStaked,tokensToRelease,token.precision,!1),await
591
+ api.db.update(\"tokens\",token),api.emit(\"unstake\",{account:account,symbol:symbol,quantity:tokensToRelease}),\"ENG\"===symbol&&await
592
+ api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:account}))}};actions.checkPendingUnstakes=async()=>{if(api.assert(\"null\"===api.sender,\"not
593
+ authorized\")){const timestamp=new Date(api.steemBlockTimestamp+\".000Z\").getTime();let
594
+ pendingUnstakes=await api.db.find(\"pendingUnstakes\",{nextTransactionTimestamp:{$lte:timestamp}}),nbPendingUnstakes=pendingUnstakes.length;for(;nbPendingUnstakes>0;){for(let
595
+ index=0;index<nbPendingUnstakes;index+=1){const pendingUnstake=pendingUnstakes[index];await
596
+ processUnstake(pendingUnstake)}pendingUnstakes=await api.db.find(\"pendingUnstakes\",{nextTransactionTimestamp:{$lte:timestamp}}),nbPendingUnstakes=pendingUnstakes.length}}},actions.enableStaking=async
597
+ payload=>{const{symbol:symbol,unstakingCooldown:unstakingCooldown,numberTransactions:numberTransactions,isSignedWithActiveKey:isSignedWithActiveKey}=payload,params=await
598
+ api.db.findOne(\"params\",{}),{enableStakingFee:enableStakingFee}=params,utilityTokenBalance=await
599
+ api.db.findOne(\"balances\",{account:api.sender,symbol:\"ENG\"}),enoughFunds=utilityTokenBalance&&api.BigNumber(utilityTokenBalance.balance).gte(enableStakingFee),authorized=void
600
+ 0===enableStakingFee||api.BigNumber(enableStakingFee).lte(0)||enoughFunds;if(api.assert(authorized,\"you
601
+ must have enough tokens to cover fees\")&&api.assert(!0===isSignedWithActiveKey,\"you
602
+ must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
603
+ symbol,\"invalid symbol\")&&api.assert(unstakingCooldown&&Number.isInteger(unstakingCooldown)&&unstakingCooldown>0&&unstakingCooldown<=18250,\"unstakingCooldown
604
+ must be an integer between 1 and 18250\")&&api.assert(numberTransactions&&Number.isInteger(numberTransactions)&&numberTransactions>0&&numberTransactions<=18250,\"numberTransactions
605
+ must be an integer between 1 and 18250\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});api.assert(null!==token,\"symbol
606
+ does not exist\")&&api.assert(token.issuer===api.sender,\"must be the issuer\")&&api.assert(void
607
+ 0===token.stakingEnabled||!1===token.stakingEnabled,\"staking already enabled\")&&(token.stakingEnabled=!0,token.totalStaked=\"0\",token.unstakingCooldown=unstakingCooldown,token.numberTransactions=numberTransactions,await
608
+ api.db.update(\"tokens\",token),api.BigNumber(enableStakingFee).gt(0)&&await
609
+ actions.transfer({to:\"null\",symbol:\"ENG\",quantity:enableStakingFee,isSignedWithActiveKey:isSignedWithActiveKey}))}},actions.stake=async
610
+ payload=>{const{symbol:symbol,quantity:quantity,to:to,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
611
+ must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
612
+ symbol&&to&&\"string\"==typeof to&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
613
+ params\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol}),finalTo=to.trim();if(api.assert(api.isValidAccountName(finalTo),\"invalid
614
+ to\")&&api.assert(null!==token,\"symbol does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
615
+ precision mismatch\")&&api.assert(!0===token.stakingEnabled,\"staking not
616
+ enabled\")&&api.assert(api.BigNumber(quantity).gt(0),\"must stake positive
617
+ quantity\")&&await subBalance(api.sender,token,quantity,\"balances\")){!1===await
618
+ addStake(finalTo,token,quantity)?await addBalance(api.sender,token,quantity,\"balances\"):(api.emit(\"stake\",{account:finalTo,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&await
619
+ api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:api.sender}))}}},actions.stakeFromContract=async
620
+ payload=>{const{symbol:symbol,quantity:quantity,to:to,callingContractInfo:callingContractInfo}=payload;if(callingContractInfo&&api.assert(symbol&&\"string\"==typeof
621
+ symbol&&to&&\"string\"==typeof to&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
622
+ params\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol}),finalTo=to.trim();if(api.assert(api.isValidAccountName(finalTo),\"invalid
623
+ to\")&&api.assert(null!==token,\"symbol does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
624
+ precision mismatch\")&&api.assert(!0===token.stakingEnabled,\"staking not
625
+ enabled\")&&api.assert(api.BigNumber(quantity).gt(0),\"must stake positive
626
+ quantity\")&&await subBalance(callingContractInfo.name,token,quantity,\"contractsBalances\")){!1===await
627
+ addStake(finalTo,token,quantity)?await addBalance(callingContractInfo.name,token,quantity,\"balances\"):(api.emit(\"stakeFromContract\",{account:finalTo,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&await
628
+ api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:finalTo}))}}};const
629
+ 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
630
+ api.db.insert(\"pendingUnstakes\",unstake)};actions.unstake=async payload=>{const{symbol:symbol,quantity:quantity,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
631
+ must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
632
+ symbol&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
633
+ params\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});api.assert(null!==token,\"symbol
634
+ does not exist\")&&api.assert(!0===token.stakingEnabled,\"staking not enabled\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
635
+ precision mismatch\")&&api.assert(api.BigNumber(quantity).gt(0),\"must unstake
636
+ 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
637
+ processCancelUnstake=async unstake=>{const{account:account,symbol:symbol,quantityLeft:quantityLeft}=unstake,balance=await
638
+ api.db.findOne(\"balances\",{account:account,symbol:symbol}),token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==balance,\"balance
639
+ does not exist\")&&api.assert(api.BigNumber(balance.pendingUnstake).gte(quantityLeft),\"overdrawn
640
+ 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
641
+ subtract\"))return await api.db.update(\"balances\",balance),api.emit(\"unstake\",{account:account,symbol:symbol,quantity:quantityLeft}),!0}return!1};actions.cancelUnstake=async
642
+ payload=>{const{txID:txID,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
643
+ must use a custom_json signed with your active key\")&&api.assert(txID&&\"string\"==typeof
644
+ txID,\"invalid params\")){const unstake=await api.db.findOne(\"pendingUnstakes\",{account:api.sender,txID:txID});api.assert(unstake,\"unstake
645
+ does not exist\")&&await processCancelUnstake(unstake)&&await api.db.remove(\"pendingUnstakes\",unstake)}},actions.enableDelegation=async
646
+ payload=>{const{symbol:symbol,undelegationCooldown:undelegationCooldown,isSignedWithActiveKey:isSignedWithActiveKey}=payload,params=await
647
+ api.db.findOne(\"params\",{}),{enableDelegationFee:enableDelegationFee}=params,utilityTokenBalance=await
648
+ api.db.findOne(\"balances\",{account:api.sender,symbol:\"ENG\"}),enoughFunds=utilityTokenBalance&&api.BigNumber(utilityTokenBalance.balance).gte(enableDelegationFee),authorized=void
649
+ 0===enableDelegationFee||api.BigNumber(enableDelegationFee).lte(0)||enoughFunds;if(api.assert(authorized,\"you
650
+ must have enough tokens to cover fees\")&&api.assert(!0===isSignedWithActiveKey,\"you
651
+ must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
652
+ symbol,\"invalid symbol\")&&api.assert(undelegationCooldown&&Number.isInteger(undelegationCooldown)&&undelegationCooldown>0&&undelegationCooldown<=18250,\"undelegationCooldown
653
+ must be an integer between 1 and 18250\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});api.assert(null!==token,\"symbol
654
+ does not exist\")&&api.assert(token.issuer===api.sender,\"must be the issuer\")&&api.assert(!0===token.stakingEnabled,\"staking
655
+ not enabled\")&&api.assert(void 0===token.delegationEnabled||!1===token.delegationEnabled,\"delegation
656
+ already enabled\")&&(token.delegationEnabled=!0,token.undelegationCooldown=undelegationCooldown,await
657
+ api.db.update(\"tokens\",token),api.BigNumber(enableDelegationFee).gt(0)&&await
658
+ actions.transfer({to:\"null\",symbol:\"ENG\",quantity:enableDelegationFee,isSignedWithActiveKey:isSignedWithActiveKey}))}},actions.delegate=async
659
+ payload=>{const{symbol:symbol,quantity:quantity,to:to,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
660
+ must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
661
+ symbol&&to&&\"string\"==typeof to&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
662
+ params\")){const finalTo=to.trim();if(api.assert(api.isValidAccountName(finalTo),\"invalid
663
+ to\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
664
+ does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
665
+ precision mismatch\")&&api.assert(!0===token.delegationEnabled,\"delegation
666
+ not enabled\")&&api.assert(finalTo!==api.sender,\"cannot delegate to yourself\")&&api.assert(api.BigNumber(quantity).gt(0),\"must
667
+ delegate positive quantity\")){const balanceFrom=await api.db.findOne(\"balances\",{account:api.sender,symbol:symbol});if(api.assert(null!==balanceFrom,\"balanceFrom
668
+ does not exist\")&&api.assert(api.BigNumber(balanceFrom.stake).gte(quantity),\"overdrawn
669
+ stake\")){void 0===balanceFrom.stake?(balanceFrom.stake=\"0\",balanceFrom.pendingUnstake=\"0\",balanceFrom.delegationsIn=\"0\",balanceFrom.delegationsOut=\"0\",balanceFrom.pendingUndelegations=\"0\"):void
670
+ 0===balanceFrom.delegationsIn&&(balanceFrom.delegationsIn=\"0\",balanceFrom.delegationsOut=\"0\",balanceFrom.pendingUndelegations=\"0\",balanceFrom.delegatedStake&&(delete
671
+ balanceFrom.delegatedStake,delete balanceFrom.receivedStake));let balanceTo=await
672
+ api.db.findOne(\"balances\",{account:finalTo,symbol:symbol});null===balanceTo?(balanceTo=balanceTemplate,balanceTo.account=finalTo,balanceTo.symbol=symbol,balanceTo=await
673
+ 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
674
+ 0===balanceTo.delegationsIn&&(balanceTo.delegationsIn=\"0\",balanceTo.delegationsOut=\"0\",balanceTo.pendingUndelegations=\"0\",balanceTo.delegatedStake&&(delete
675
+ balanceTo.delegatedStake,delete balanceTo.receivedStake));let delegation=await
676
+ api.db.findOne(\"delegations\",{to:finalTo,from:api.sender,symbol:symbol});const
677
+ 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
678
+ api.db.update(\"balances\",balanceFrom),balanceTo.delegationsIn=calculateBalance(balanceTo.delegationsIn,quantity,token.precision,!0),await
679
+ 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
680
+ api.db.insert(\"delegations\",delegation),api.emit(\"delegate\",{to:finalTo,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&(await
681
+ api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:api.sender}),await
682
+ 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
683
+ api.db.update(\"balances\",balanceFrom),balanceTo.delegationsIn=calculateBalance(balanceTo.delegationsIn,quantity,token.precision,!0),await
684
+ api.db.update(\"balances\",balanceTo),delegation.quantity=calculateBalance(delegation.quantity,quantity,token.precision,!0),delegation.updated=timestamp,await
685
+ api.db.update(\"delegations\",delegation),api.emit(\"delegate\",{to:finalTo,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&(await
686
+ api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:api.sender}),await
687
+ api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:finalTo})))}}}}},actions.undelegate=async
688
+ payload=>{const{symbol:symbol,quantity:quantity,from:from,isSignedWithActiveKey:isSignedWithActiveKey}=payload;if(api.assert(!0===isSignedWithActiveKey,\"you
689
+ must use a custom_json signed with your active key\")&&api.assert(symbol&&\"string\"==typeof
690
+ symbol&&from&&\"string\"==typeof from&&quantity&&\"string\"==typeof quantity&&!api.BigNumber(quantity).isNaN(),\"invalid
691
+ params\")){const finalFrom=from.trim();if(api.assert(finalFrom.length>=3&&finalFrom.length<=16,\"invalid
692
+ from\")){const token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==token,\"symbol
693
+ does not exist\")&&api.assert(countDecimals(quantity)<=token.precision,\"symbol
694
+ precision mismatch\")&&api.assert(!0===token.delegationEnabled,\"delegation
695
+ not enabled\")&&api.assert(finalFrom!==api.sender,\"cannot undelegate from
696
+ yourself\")&&api.assert(api.BigNumber(quantity).gt(0),\"must undelegate positive
697
+ quantity\")){const balanceTo=await api.db.findOne(\"balances\",{account:api.sender,symbol:symbol});if(api.assert(null!==balanceTo,\"balanceTo
698
+ does not exist\")&&api.assert(api.BigNumber(balanceTo.delegationsOut).gte(quantity),\"overdrawn
699
+ delegation\")){const balanceFrom=await api.db.findOne(\"balances\",{account:finalFrom,symbol:symbol});if(api.assert(null!==balanceFrom,\"balanceFrom
700
+ does not exist\")){const delegation=await api.db.findOne(\"delegations\",{to:finalFrom,from:api.sender,symbol:symbol});if(api.assert(null!==delegation,\"delegation
701
+ does not exist\")&&api.assert(api.BigNumber(delegation.quantity).gte(quantity),\"overdrawn
702
+ delegation\")){balanceTo.pendingUndelegations=calculateBalance(balanceFrom.pendingUndelegations,quantity,token.precision,!0),balanceTo.delegationsOut=calculateBalance(balanceTo.delegationsOut,quantity,token.precision,!1),await
703
+ api.db.update(\"balances\",balanceTo),balanceFrom.delegationsIn=calculateBalance(balanceFrom.delegationsIn,quantity,token.precision,!1),await
704
+ api.db.update(\"balances\",balanceFrom),delegation.quantity=calculateBalance(delegation.quantity,quantity,token.precision,!1),api.BigNumber(delegation.quantity).gt(0)?await
705
+ api.db.update(\"delegations\",delegation):await api.db.remove(\"delegations\",delegation);const
706
+ 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
707
+ api.db.insert(\"pendingUndelegations\",undelegation),api.emit(\"undelegateStart\",{from:finalFrom,symbol:symbol,quantity:quantity}),\"ENG\"===symbol&&await
708
+ api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:finalFrom})}}}}}}};const
709
+ processUndelegation=async undelegation=>{const{account:account,symbol:symbol,quantity:quantity}=undelegation,balance=await
710
+ api.db.findOne(\"balances\",{account:account,symbol:symbol}),token=await api.db.findOne(\"tokens\",{symbol:symbol});if(api.assert(null!==balance,\"balance
711
+ 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
712
+ 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
713
+ api.executeSmartContract(\"witnesses\",\"updateWitnessesApprovals\",{account:account}))}};actions.checkPendingUndelegations=async()=>{if(api.assert(\"null\"===api.sender,\"not
714
+ authorized\")){const timestamp=new Date(api.steemBlockTimestamp+\".000Z\").getTime();let
715
+ pendingUndelegations=await api.db.find(\"pendingUndelegations\",{completeTimestamp:{$lte:timestamp}}),nbPendingUndelegations=pendingUndelegations.length;for(;nbPendingUndelegations>0;){for(let
716
+ index=0;index<nbPendingUndelegations;index+=1){const pendingUndelegation=pendingUndelegations[index];await
717
+ processUndelegation(pendingUndelegation)}pendingUndelegations=await api.db.find(\"pendingUndelegations\",{completeTimestamp:{$lte:timestamp}}),nbPendingUndelegations=pendingUndelegations.length}}};\n \n const
718
+ execute = async function () {\n try {\n if (api.action
719
+ && typeof api.action === ''string'' && typeof actions[api.action] === ''function'')
720
+ {\n if (api.action !== ''createSSC'') {\n actions.createSSC
721
+ = null;\n }\n await actions[api.action](api.payload);\n done(null);\n }
722
+ else {\n done(''invalid action'');\n }\n }
723
+ catch (error) {\n done(error);\n }\n }\n \n execute();\n }\n\n wrapper();\n ","codeHash":"d3ab1afa743f5322eb1b5da7ada99c43f7d26f47cfaab98acb9322c929b23ea6","tables":{"tokens_tokens":{"size":0,"hash":"fa99c96c04b41ec8efc70c3521ff42240b7322c4a130e260da3a69dfd317df1c","nbIndexes":1},"tokens_balances":{"size":0,"hash":"5dff496d3d70b5b60b3137cd2637162ea354e7c08e4e5376695805b06a4a0018","nbIndexes":1},"tokens_contractsBalances":{"size":0,"hash":"9b81b17a7ba695e35bc62c7a48f811cbcf182676bc3f8f9d88967a5e2a06e212","nbIndexes":1},"tokens_params":{"size":0,"hash":"cd372fb85148700fa88095e3492d3f9f5beb43e555e5ff26d95f5a6adc36f8e6","nbIndexes":0},"tokens_pendingUnstakes":{"size":0,"hash":"28d69d6b5110ec4850d1d37c975691cca41588ae7716b36a77c48e5278cfd44d","nbIndexes":2},"tokens_delegations":{"size":0,"hash":"f4739c72c1015df4feefe272a184823cf0d362d6eb0e6d1963ea55a5406f44d1","nbIndexes":2},"tokens_pendingUndelegations":{"size":0,"hash":"c39d9706ff037b43a9566b7ddf3fc2679bd84301d343369db2413e9c801be1ea","nbIndexes":2}},"version":17}}'
724
+ recorded_at: Sat, 30 Jul 2022 23:22:58 GMT
725
+ recorded_with: VCR 6.1.0
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: https://api.steem-engine.com/rpc/contracts
5
+ uri: https://api.steem-engine.net/rpc/contracts
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"method":"find","params":{"contract":"tokens","table":"transfers","query":{"symbol":""},"limit":0},"jsonrpc":"2.0","id":2}'
@@ -44,7 +44,7 @@ http_interactions:
44
44
  recorded_at: Sat, 07 Nov 2020 20:13:30 GMT
45
45
  - request:
46
46
  method: post
47
- uri: https://api.steem-engine.com/rpc/contracts
47
+ uri: https://api.steem-engine.net/rpc/contracts
48
48
  body:
49
49
  encoding: UTF-8
50
50
  string: '{"method":"find","params":{"contract":"tokens","table":"balances","query":{"symbol":"STINGY"}},"jsonrpc":"2.0","id":1}'
@@ -86,4 +86,82 @@ http_interactions:
86
86
  encoding: ASCII-8BIT
87
87
  string: '{"jsonrpc":"2.0","id":1,"result":[{"_id":363,"account":"inertia","symbol":"STINGY","balance":"36.92931281"},{"_id":364,"account":"ausbitbank","symbol":"STINGY","balance":"43.97961424"},{"_id":386,"account":"anthonyadavisii","symbol":"STINGY","balance":"44.97668238"},{"_id":436,"account":"noflyzoe","symbol":"STINGY","balance":"0.00000000"},{"_id":501,"account":"eonwarped","symbol":"STINGY","balance":"172.07799631"},{"_id":509,"account":"freebornangel","symbol":"STINGY","balance":"0.00000000"},{"_id":526,"account":"flagawhale","symbol":"STINGY","balance":"6.19853502"},{"_id":527,"account":"admiralbot","symbol":"STINGY","balance":"1.34385669"},{"_id":943,"account":"whatsup","symbol":"STINGY","balance":"15.73333608"},{"_id":1013,"account":"pjau","symbol":"STINGY","balance":"48.93149963"},{"_id":1088,"account":"themarkymark","symbol":"STINGY","balance":"0.00000000"},{"_id":1189,"account":"enforcer48","symbol":"STINGY","balance":"80.20820734"},{"_id":1436,"account":"ackza","symbol":"STINGY","balance":"0.00000000"},{"_id":14375,"account":"aneilpatel","symbol":"STINGY","balance":"0.00100000"},{"_id":14873,"account":"ipromote","symbol":"STINGY","balance":"0.32115167"},{"_id":14874,"account":"boinger","symbol":"STINGY","balance":"0.00000000"},{"_id":14875,"account":"mrkebab","symbol":"STINGY","balance":"8.02061781"},{"_id":14876,"account":"gamblingman","symbol":"STINGY","balance":"0.00000000"},{"_id":14877,"account":"rollingbones","symbol":"STINGY","balance":"0.00000000"},{"_id":27031,"account":"beggars","symbol":"STINGY","balance":"0.24527928"},{"_id":32967,"account":"sbi-booster","symbol":"STINGY","balance":"3.05576375"},{"_id":38794,"account":"gtg","symbol":"STINGY","balance":"134.33062049","stake":"0","delegatedStake":"0","receivedStake":"0","pendingUnstake":"0"},{"_id":40769,"account":"rishi556","symbol":"STINGY","balance":"0.00085376","stake":"0","delegatedStake":"0","receivedStake":"0","pendingUnstake":"0"},{"_id":101534,"account":"mathowl","symbol":"STINGY","balance":"25.34028885","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":224856,"account":"onealfa","symbol":"STINGY","balance":"0.00000000","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":226366,"account":"emrebeyler","symbol":"STINGY","balance":"18.58740409","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":312444,"account":"bluemist","symbol":"STINGY","balance":"3.00000000","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":410880,"account":"freebornsociety","symbol":"STINGY","balance":"65.29767916","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":436527,"account":"buildawhale","symbol":"STINGY","balance":"0.00000000","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":445673,"account":"justlee87","symbol":"STINGY","balance":"42.00380343","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":455433,"account":"r0nd0n","symbol":"STINGY","balance":"0.13683141","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":474687,"account":"mulletwang","symbol":"STINGY","balance":"1.00000000","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":475578,"account":"steemtorch","symbol":"STINGY","balance":"389.16542368","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"}]}'
88
88
  recorded_at: Sat, 07 Nov 2020 20:13:31 GMT
89
- recorded_with: VCR 6.0.0
89
+ - request:
90
+ method: post
91
+ uri: https://api.steem-engine.net/rpc/contracts
92
+ body:
93
+ encoding: UTF-8
94
+ string: '{"method":"find","params":{"contract":"tokens","table":"transfers","query":{"symbol":""},"limit":0},"jsonrpc":"2.0","id":2}'
95
+ headers:
96
+ Content-Type:
97
+ - application/json
98
+ User-Agent:
99
+ - radiator/0.4.9
100
+ Accept-Encoding:
101
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
102
+ Accept:
103
+ - "*/*"
104
+ response:
105
+ status:
106
+ code: 200
107
+ message: OK
108
+ headers:
109
+ Server:
110
+ - nginx/1.10.3 (Ubuntu)
111
+ Date:
112
+ - Sat, 30 Jul 2022 23:22:54 GMT
113
+ Content-Type:
114
+ - application/json; charset=utf-8
115
+ Content-Length:
116
+ - '38'
117
+ Connection:
118
+ - keep-alive
119
+ X-Powered-By:
120
+ - Express
121
+ Access-Control-Allow-Origin:
122
+ - "*"
123
+ body:
124
+ encoding: UTF-8
125
+ string: '{"jsonrpc":"2.0","id":2,"result":null}'
126
+ recorded_at: Sat, 30 Jul 2022 23:22:54 GMT
127
+ - request:
128
+ method: post
129
+ uri: https://api.steem-engine.net/rpc/contracts
130
+ body:
131
+ encoding: UTF-8
132
+ string: '{"method":"find","params":{"contract":"tokens","table":"balances","query":{"symbol":"STINGY"}},"jsonrpc":"2.0","id":1}'
133
+ headers:
134
+ Content-Type:
135
+ - application/json
136
+ User-Agent:
137
+ - radiator/0.4.9
138
+ Accept-Encoding:
139
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
140
+ Accept:
141
+ - "*/*"
142
+ response:
143
+ status:
144
+ code: 200
145
+ message: OK
146
+ headers:
147
+ Server:
148
+ - nginx/1.10.3 (Ubuntu)
149
+ Date:
150
+ - Sat, 30 Jul 2022 23:22:55 GMT
151
+ Content-Type:
152
+ - application/json; charset=utf-8
153
+ Transfer-Encoding:
154
+ - chunked
155
+ Connection:
156
+ - keep-alive
157
+ Vary:
158
+ - Accept-Encoding
159
+ X-Powered-By:
160
+ - Express
161
+ Access-Control-Allow-Origin:
162
+ - "*"
163
+ body:
164
+ encoding: ASCII-8BIT
165
+ string: '{"jsonrpc":"2.0","id":1,"result":[{"_id":363,"account":"inertia","symbol":"STINGY","balance":"36.92931281"},{"_id":364,"account":"ausbitbank","symbol":"STINGY","balance":"43.97961424"},{"_id":386,"account":"anthonyadavisii","symbol":"STINGY","balance":"44.97668238"},{"_id":436,"account":"noflyzoe","symbol":"STINGY","balance":"0.00000000"},{"_id":501,"account":"eonwarped","symbol":"STINGY","balance":"172.07799631"},{"_id":509,"account":"freebornangel","symbol":"STINGY","balance":"0.00000000"},{"_id":526,"account":"flagawhale","symbol":"STINGY","balance":"6.19853502"},{"_id":527,"account":"admiralbot","symbol":"STINGY","balance":"1.34385669"},{"_id":943,"account":"whatsup","symbol":"STINGY","balance":"15.73333608"},{"_id":1013,"account":"pjau","symbol":"STINGY","balance":"48.93149963"},{"_id":1088,"account":"themarkymark","symbol":"STINGY","balance":"0.00000000"},{"_id":1189,"account":"enforcer48","symbol":"STINGY","balance":"80.20820734"},{"_id":1436,"account":"ackza","symbol":"STINGY","balance":"0.00000000"},{"_id":14375,"account":"aneilpatel","symbol":"STINGY","balance":"0.00100000"},{"_id":14873,"account":"ipromote","symbol":"STINGY","balance":"0.32115167"},{"_id":14874,"account":"boinger","symbol":"STINGY","balance":"0.00000000"},{"_id":14875,"account":"mrkebab","symbol":"STINGY","balance":"8.02061781"},{"_id":14876,"account":"gamblingman","symbol":"STINGY","balance":"0.00000000"},{"_id":14877,"account":"rollingbones","symbol":"STINGY","balance":"0.00000000"},{"_id":27031,"account":"beggars","symbol":"STINGY","balance":"0.24527928"},{"_id":32967,"account":"sbi-booster","symbol":"STINGY","balance":"3.05576375"},{"_id":38794,"account":"gtg","symbol":"STINGY","balance":"134.33062049","stake":"0","delegatedStake":"0","receivedStake":"0","pendingUnstake":"0"},{"_id":40769,"account":"rishi556","symbol":"STINGY","balance":"0.00085376","stake":"0","delegatedStake":"0","receivedStake":"0","pendingUnstake":"0"},{"_id":101534,"account":"mathowl","symbol":"STINGY","balance":"25.34028885","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":224856,"account":"onealfa","symbol":"STINGY","balance":"0.00000000","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":226366,"account":"emrebeyler","symbol":"STINGY","balance":"18.58740409","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":312444,"account":"bluemist","symbol":"STINGY","balance":"3.00000000","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":410880,"account":"freebornsociety","symbol":"STINGY","balance":"65.29767916","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":436527,"account":"buildawhale","symbol":"STINGY","balance":"0.00000000","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":445673,"account":"justlee87","symbol":"STINGY","balance":"42.00380343","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":455433,"account":"r0nd0n","symbol":"STINGY","balance":"0.13683141","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":474687,"account":"mulletwang","symbol":"STINGY","balance":"1.00000000","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"},{"_id":475578,"account":"steemtorch","symbol":"STINGY","balance":"389.16542368","stake":"0","pendingUnstake":"0","delegationsIn":"0","delegationsOut":"0","pendingUndelegations":"0"}]}'
166
+ recorded_at: Sat, 30 Jul 2022 23:22:55 GMT
167
+ recorded_with: VCR 6.1.0