Home Reference Source

packages/oo7-substrate/src/index.js

  1. const nacl = require('tweetnacl')
  2. const { ss58Decode, ss58Encode, setNetworkDefault } = require('./ss58')
  3. const { VecU8, AccountId, Hash, VoteThreshold, Moment, Balance, BlockNumber, AccountIndex, TransactionEra, Tuple, Permill, Perbill, reviver } = require('./types')
  4. const { decode, encode, addCodecTransform } = require('./codec')
  5. const { pretty } = require('./pretty')
  6. const { post } = require('./transact')
  7. const { secretStore } = require('./secretStore')
  8. const { addressBook } = require('./addressBook')
  9. const { stringToSeed, stringToBytes, hexToBytes, bytesToHex, toLEHex, toLE, leToNumber, leHexToNumber, siPrefix } = require('./utils')
  10. const { storageKey } = require('./storageBond')
  11. const { initRuntime, runtime, calls, runtimePromise, callsPromise, chain, system, state, runtimeUp } = require('./bonds')
  12. const { nodeService, setNodeUri } = require('./nodeService')
  13. const denominationInfo = require('./denominationInfo')
  14. const { metadata } = require('./metadata')
  15.  
  16. function tally(x) {
  17. var r = [0, 0]
  18. x.forEach(v => r[v ? 1 : 0]++)
  19. return {aye: r[1], nay: r[0]}
  20. }
  21.  
  22. function tallyAmounts(x) {
  23. var r = [0, 0]
  24. x.forEach(([v, b]) => r[v ? 1 : 0] += b)
  25. return {aye: r[1], nay: r[0]}
  26. }
  27.  
  28. // TODO: receipts from tx
  29. // TODO: compact transactions (switch out account for index when possible)
  30.  
  31. if (typeof window !== 'undefined') {
  32. window.ss58Encode = ss58Encode
  33. window.ss58Decode = ss58Decode
  34. window.bytesToHex = bytesToHex
  35. window.stringToBytes = stringToBytes
  36. window.hexToBytes = hexToBytes
  37. window.toLE = toLE
  38. window.leToNumber = leToNumber
  39. window.storageKey = storageKey
  40. window.encode = encode
  41. window.decode = decode
  42. window.pretty = pretty
  43. window.addCodecTransform = addCodecTransform
  44. window.nodeService = nodeService
  45. window.secretStore = secretStore
  46. window.nacl = nacl
  47. window.post = post
  48. window.AccountId = AccountId
  49. window.AccountIndex = AccountIndex
  50. window.storageKey = storageKey
  51. }
  52.  
  53. module.exports = {
  54. ss58Decode, ss58Encode, setNetworkDefault,
  55. // utils
  56. stringToSeed, stringToBytes, hexToBytes, bytesToHex, toLEHex, leHexToNumber, toLE, leToNumber, reviver,
  57. // types
  58. AccountId, AccountIndex, TransactionEra, Hash, VoteThreshold, Moment, Balance, BlockNumber, Tuple, VecU8,
  59. Permill, Perbill,
  60. pretty, encode, decode, addCodecTransform,
  61. secretStore, addressBook,
  62. post,
  63. denominationInfo,
  64. nodeService, setNodeUri,
  65. metadata,
  66. // bonds
  67. initRuntime, runtime, calls, runtimePromise, callsPromise, chain, system, state, runtimeUp
  68. }