@prosopo/scripts 0.1.18 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/dist/cli/index.d.ts +2 -0
  2. package/dist/cli/index.d.ts.map +1 -0
  3. package/dist/cli/index.js +145 -0
  4. package/dist/cli/index.js.map +1 -0
  5. package/dist/contract/deploy/dapp.d.ts +3 -0
  6. package/dist/contract/deploy/dapp.d.ts.map +1 -0
  7. package/dist/contract/deploy/dapp.js +41 -0
  8. package/dist/contract/deploy/dapp.js.map +1 -0
  9. package/dist/contract/deploy/index.d.ts +3 -0
  10. package/dist/contract/deploy/index.d.ts.map +1 -0
  11. package/dist/contract/deploy/index.js +16 -0
  12. package/dist/contract/deploy/index.js.map +1 -0
  13. package/dist/contract/deploy/protocol.d.ts +3 -0
  14. package/dist/contract/deploy/protocol.d.ts.map +1 -0
  15. package/dist/contract/deploy/protocol.js +53 -0
  16. package/dist/contract/deploy/protocol.js.map +1 -0
  17. package/dist/contract/import.d.ts +4 -0
  18. package/dist/contract/import.d.ts.map +1 -0
  19. package/dist/contract/import.js +21 -0
  20. package/dist/contract/import.js.map +1 -0
  21. package/dist/contract/index.d.ts +3 -0
  22. package/dist/contract/index.d.ts.map +1 -0
  23. package/dist/contract/index.js +16 -0
  24. package/dist/contract/index.js.map +1 -0
  25. package/dist/index.d.ts +5 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +18 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/scripts/addCopyrightNotice.d.ts +2 -0
  30. package/dist/scripts/addCopyrightNotice.d.ts.map +1 -0
  31. package/dist/scripts/addCopyrightNotice.js +104 -0
  32. package/dist/scripts/addCopyrightNotice.js.map +1 -0
  33. package/dist/scripts/bytesToHex.d.ts +2 -0
  34. package/dist/scripts/bytesToHex.d.ts.map +1 -0
  35. package/dist/scripts/bytesToHex.js +22 -0
  36. package/dist/scripts/bytesToHex.js.map +1 -0
  37. package/dist/scripts/convertAccount.d.ts +2 -0
  38. package/dist/scripts/convertAccount.d.ts.map +1 -0
  39. package/dist/scripts/convertAccount.js +38 -0
  40. package/dist/scripts/convertAccount.js.map +1 -0
  41. package/dist/scripts/encodeDecode.d.ts +2 -0
  42. package/dist/scripts/encodeDecode.d.ts.map +1 -0
  43. package/dist/scripts/encodeDecode.js +65 -0
  44. package/dist/scripts/encodeDecode.js.map +1 -0
  45. package/dist/scripts/generateMnemonic.d.ts +2 -0
  46. package/dist/scripts/generateMnemonic.d.ts.map +1 -0
  47. package/dist/scripts/generateMnemonic.js +28 -0
  48. package/dist/scripts/generateMnemonic.js.map +1 -0
  49. package/dist/scripts/getBalance.d.ts +2 -0
  50. package/dist/scripts/getBalance.d.ts.map +1 -0
  51. package/dist/scripts/getBalance.js +15 -0
  52. package/dist/scripts/getBalance.js.map +1 -0
  53. package/dist/scripts/getBlock.d.ts +2 -0
  54. package/dist/scripts/getBlock.d.ts.map +1 -0
  55. package/dist/scripts/getBlock.js +32 -0
  56. package/dist/scripts/getBlock.js.map +1 -0
  57. package/dist/scripts/getContractInfoOf.d.ts +2 -0
  58. package/dist/scripts/getContractInfoOf.d.ts.map +1 -0
  59. package/dist/scripts/getContractInfoOf.js +53 -0
  60. package/dist/scripts/getContractInfoOf.js.map +1 -0
  61. package/dist/scripts/getExistentialDeposit.d.ts +2 -0
  62. package/dist/scripts/getExistentialDeposit.d.ts.map +1 -0
  63. package/dist/scripts/getExistentialDeposit.js +39 -0
  64. package/dist/scripts/getExistentialDeposit.js.map +1 -0
  65. package/dist/scripts/getRandomProvider.d.ts +2 -0
  66. package/dist/scripts/getRandomProvider.d.ts.map +1 -0
  67. package/dist/scripts/getRandomProvider.js +38 -0
  68. package/dist/scripts/getRandomProvider.js.map +1 -0
  69. package/dist/scripts/getStorage.d.ts +2 -0
  70. package/dist/scripts/getStorage.d.ts.map +1 -0
  71. package/dist/scripts/getStorage.js +36 -0
  72. package/dist/scripts/getStorage.js.map +1 -0
  73. package/dist/scripts/getValidators.d.ts +2 -0
  74. package/dist/scripts/getValidators.d.ts.map +1 -0
  75. package/dist/scripts/getValidators.js +32 -0
  76. package/dist/scripts/getValidators.js.map +1 -0
  77. package/dist/scripts/hash.d.ts +2 -0
  78. package/dist/scripts/hash.d.ts.map +1 -0
  79. package/dist/scripts/hash.js +56 -0
  80. package/dist/scripts/hash.js.map +1 -0
  81. package/dist/scripts/hexToBytes.d.ts +2 -0
  82. package/dist/scripts/hexToBytes.d.ts.map +1 -0
  83. package/dist/scripts/hexToBytes.js +19 -0
  84. package/dist/scripts/hexToBytes.js.map +1 -0
  85. package/dist/scripts/mnemonicFromSeed.d.ts +2 -0
  86. package/dist/scripts/mnemonicFromSeed.d.ts.map +1 -0
  87. package/dist/scripts/mnemonicFromSeed.js +30 -0
  88. package/dist/scripts/mnemonicFromSeed.js.map +1 -0
  89. package/dist/scripts/populateTxAndSign.d.ts +2 -0
  90. package/dist/scripts/populateTxAndSign.d.ts.map +1 -0
  91. package/dist/scripts/populateTxAndSign.js +65 -0
  92. package/dist/scripts/populateTxAndSign.js.map +1 -0
  93. package/dist/scripts/sendFunds.d.ts +2 -0
  94. package/dist/scripts/sendFunds.d.ts.map +1 -0
  95. package/dist/scripts/sendFunds.js +33 -0
  96. package/dist/scripts/sendFunds.js.map +1 -0
  97. package/dist/setup/dapp.d.ts +4 -0
  98. package/dist/setup/dapp.d.ts.map +1 -0
  99. package/dist/setup/dapp.js +35 -0
  100. package/dist/setup/dapp.js.map +1 -0
  101. package/dist/setup/funds.d.ts +23 -0
  102. package/dist/setup/funds.d.ts.map +1 -0
  103. package/dist/setup/funds.js +102 -0
  104. package/dist/setup/funds.js.map +1 -0
  105. package/dist/setup/index.d.ts +5 -0
  106. package/dist/setup/index.d.ts.map +1 -0
  107. package/dist/setup/index.js +18 -0
  108. package/dist/setup/index.js.map +1 -0
  109. package/dist/setup/provider.d.ts +5 -0
  110. package/dist/setup/provider.d.ts.map +1 -0
  111. package/dist/setup/provider.js +84 -0
  112. package/dist/setup/provider.js.map +1 -0
  113. package/dist/setup/setup.d.ts +2 -0
  114. package/dist/setup/setup.d.ts.map +1 -0
  115. package/dist/setup/setup.js +151 -0
  116. package/dist/setup/setup.js.map +1 -0
  117. package/dist/util/exec.d.ts +10 -0
  118. package/dist/util/exec.d.ts.map +1 -0
  119. package/dist/util/exec.js +58 -0
  120. package/dist/util/exec.js.map +1 -0
  121. package/dist/util/index.d.ts +4 -0
  122. package/dist/util/index.d.ts.map +1 -0
  123. package/dist/util/index.js +17 -0
  124. package/dist/util/index.js.map +1 -0
  125. package/dist/util/loadContractFiles.d.ts +4 -0
  126. package/dist/util/loadContractFiles.d.ts.map +1 -0
  127. package/dist/util/loadContractFiles.js +54 -0
  128. package/dist/util/loadContractFiles.js.map +1 -0
  129. package/dist/util/updateEnv.d.ts +4 -0
  130. package/dist/util/updateEnv.d.ts.map +1 -0
  131. package/dist/util/updateEnv.js +45 -0
  132. package/dist/util/updateEnv.js.map +1 -0
  133. package/package.json +20 -20
@@ -0,0 +1 @@
1
+ {"version":3,"file":"populateTxAndSign.d.ts","sourceRoot":"","sources":["../../src/scripts/populateTxAndSign.ts"],"names":[],"mappings":""}
@@ -0,0 +1,65 @@
1
+ // Copyright 2021-2022 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ // #!/usr/bin/env node
15
+ // import { hexToString, hexToU8a, u8aToHex } from '@polkadot/util'
16
+ // import { Environment } from '../src/env'
17
+ // import { blake2AsU8a, encodeAddress } from '@polkadot/util-crypto'
18
+ // import { Option, GenericAccountId } from '@polkadot/types'
19
+ //
20
+ // require('dotenv').config()
21
+ export {};
22
+ // async function main () {
23
+ // const env = new Environment(undefined)
24
+ // await env.isReady()
25
+ // const contractApi = new ProsopoContractApi(env)
26
+ // const serviceOrigin = 'http://localhost:9229'
27
+ // const dappContract = '5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y'
28
+ // const mnemonic = '//Alice'
29
+ //
30
+ // if (mnemonic) {
31
+ // const signerPair = env.network.keyring.addFromMnemonic(mnemonic)
32
+ // const senderAddress = signerPair.address
33
+ // const davePair = env.network.keyring.addFromMnemonic('//Dave')
34
+ // console.log(davePair.address)
35
+ // // let emptyOption: <T extends Codec> (typeName: keyof InterfaceTypes) => Option<T>;
36
+ // const args = [serviceOrigin, dappContract, new Option(env.network.registry, GenericAccountId)]
37
+ // const method = 'dappRegister'
38
+ // const encodedArgs = contractApi.encodeArgs(method, args)
39
+ // console.log(new Option(env.network.registry, GenericAccountId).toU8a())
40
+ // // console.log(u8aToHex(encodedArgs));
41
+ // console.log(encodedArgs)
42
+ // const populatedTx = await env.contract?.populateTransaction.dappRegister(...encodedArgs, { gasLimit: 8705000000 })
43
+ // console.log(encodeAddress(populatedTx!.callParams!.dest))
44
+ // console.log(populatedTx!.callParams!.gasLimit.toString())
45
+ // console.log(u8aToHex(populatedTx!.callParams!.inputData))
46
+ // const payload = u8aToHex(populatedTx!.callParams!.inputData)
47
+ // console.log('Payload generated with no signer present in environment\n')
48
+ // console.log(`Payload: ${payload}`)
49
+ // await env.changeSigner(mnemonic)
50
+ // const signature = signerPair.sign(hexToU8a(payload), { withType: true })
51
+ // console.log(`Signature: ${u8aToHex(signature)}`)
52
+ // console.log(`Decoding 0x42b45efa: ${hexToString('0x42b45efa')}`)
53
+ // console.log(`Decoding 0x1501: ${hexToString('0x1501')}`)
54
+ // // decodeU8a
55
+ // console.log(new Option(env.network.registry, GenericAccountId, null).toU8a())
56
+ // process.exit(0)
57
+ // }
58
+ // }
59
+ //
60
+ // main()
61
+ // .catch((error) => {
62
+ // console.error(error)
63
+ // process.exit()
64
+ // })
65
+ //# sourceMappingURL=populateTxAndSign.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"populateTxAndSign.js","sourceRoot":"","sources":["../../src/scripts/populateTxAndSign.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,sBAAsB;AACtB,mEAAmE;AACnE,2CAA2C;AAC3C,qEAAqE;AACrE,6DAA6D;AAC7D,EAAE;AACF,6BAA6B;;AAE7B,2BAA2B;AAC3B,6CAA6C;AAC7C,0BAA0B;AAC1B,sDAAsD;AACtD,oDAAoD;AACpD,8EAA8E;AAC9E,iCAAiC;AACjC,EAAE;AACF,sBAAsB;AACtB,2EAA2E;AAC3E,mDAAmD;AACnD,yEAAyE;AACzE,wCAAwC;AACxC,+FAA+F;AAC/F,yGAAyG;AACzG,wCAAwC;AACxC,mEAAmE;AACnE,kFAAkF;AAClF,iDAAiD;AACjD,mCAAmC;AACnC,6HAA6H;AAC7H,oEAAoE;AACpE,oEAAoE;AACpE,oEAAoE;AACpE,uEAAuE;AACvE,mFAAmF;AACnF,6CAA6C;AAC7C,2CAA2C;AAC3C,mFAAmF;AACnF,2DAA2D;AAC3D,2EAA2E;AAC3E,mEAAmE;AACnE,uBAAuB;AACvB,wFAAwF;AACxF,0BAA0B;AAC1B,QAAQ;AACR,IAAI;AACJ,EAAE;AACF,SAAS;AACT,0BAA0B;AAC1B,+BAA+B;AAC/B,yBAAyB;AACzB,SAAS"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sendFunds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendFunds.d.ts","sourceRoot":"","sources":["../../src/scripts/sendFunds.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ // Copyright 2021-2023 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { BN } from '@polkadot/util';
15
+ import { Environment } from '@prosopo/env';
16
+ import { at } from '@prosopo/util';
17
+ import { config } from 'dotenv';
18
+ import { defaultConfig, getPairType, getSs58Format } from '@prosopo/cli';
19
+ import { getPair } from '@prosopo/common';
20
+ import { sendFunds } from '../setup/index.js';
21
+ config();
22
+ async function main(account) {
23
+ const pair = await getPair(getPairType(), getSs58Format(), '//Alice');
24
+ const env = new Environment(pair, defaultConfig());
25
+ await env.isReady();
26
+ await sendFunds(env, account, 'Provider', new BN('100000000000000000'));
27
+ process.exit();
28
+ }
29
+ main(at(process.argv.slice(2), 0).trim()).catch((error) => {
30
+ console.error(error);
31
+ process.exit();
32
+ });
33
+ //# sourceMappingURL=sendFunds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendFunds.js","sourceRoot":"","sources":["../../src/scripts/sendFunds.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C,MAAM,EAAE,CAAA;AAER,KAAK,UAAU,IAAI,CAAC,OAAe;IAC/B,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,EAAE,aAAa,EAAE,EAAE,SAAS,CAAC,CAAA;IACrE,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE,aAAa,EAAE,CAAC,CAAA;IAClD,MAAM,GAAG,CAAC,OAAO,EAAE,CAAA;IACnB,MAAM,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAA;IACvE,OAAO,CAAC,IAAI,EAAE,CAAA;AAClB,CAAC;AAED,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACtD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACpB,OAAO,CAAC,IAAI,EAAE,CAAA;AAClB,CAAC,CAAC,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { IDappAccount } from '@prosopo/types';
2
+ import { ProviderEnvironment } from '@prosopo/types-env';
3
+ export declare function setupDapp(env: ProviderEnvironment, dapp: IDappAccount): Promise<void>;
4
+ //# sourceMappingURL=dapp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dapp.d.ts","sourceRoot":"","sources":["../../src/setup/dapp.ts"],"names":[],"mappings":"AAaA,OAAO,EAAmB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAIxD,wBAAsB,SAAS,CAAC,GAAG,EAAE,mBAAmB,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAoB3F"}
@@ -0,0 +1,35 @@
1
+ // Copyright 2021-2023 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { DappPayee } from '@prosopo/types';
15
+ import { Tasks } from '@prosopo/provider';
16
+ import { wrapQuery } from '@prosopo/contract';
17
+ export async function setupDapp(env, dapp) {
18
+ const logger = env.logger;
19
+ if (dapp.pair) {
20
+ await env.changeSigner(dapp.pair);
21
+ const tasks = new Tasks(env);
22
+ try {
23
+ const dappResult = await wrapQuery(tasks.contract.query.getDapp, tasks.contract.query)(dapp.contractAccount);
24
+ logger.info(' - dapp is already registered');
25
+ logger.info('Dapp', dappResult);
26
+ }
27
+ catch (e) {
28
+ logger.info(' - dappRegister');
29
+ await tasks.contract.tx.dappRegister(dapp.contractAccount, DappPayee.dapp);
30
+ logger.info(' - dappFund');
31
+ await tasks.contract.tx.dappFund(dapp.contractAccount, { value: dapp.fundAmount });
32
+ }
33
+ }
34
+ }
35
+ //# sourceMappingURL=dapp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dapp.js","sourceRoot":"","sources":["../../src/setup/dapp.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;A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AAC,CAAA;SACrF;KACJ;AACL,CAAC"}
@@ -0,0 +1,23 @@
1
+ /// <reference types="bn.js" />
2
+ import { AnyNumber } from '@polkadot/types-codec/types';
3
+ import { BN } from '@polkadot/util';
4
+ import { ProsopoEnvironment } from '@prosopo/types-env';
5
+ /** Send funds from one of the development accounts to another account. */
6
+ export declare function sendFunds(env: ProsopoEnvironment, address: string, who: string, amount: AnyNumber): Promise<void>;
7
+ /**
8
+ * Takes the providerStakeDefault and works out if multiplying it by 100 or
9
+ * stakeMultiplier is greater than the maxStake. If it is, it returns the maxStake
10
+ * If chain decimals = 12, 1 UNIT = 1e12
11
+ * @param env
12
+ * @param providerStakeDefault
13
+ * @param stakeMultiplier
14
+ */
15
+ export declare function getStakeAmount(env: ProsopoEnvironment, providerStakeDefault: BN, stakeMultiplier?: number): BN;
16
+ /**
17
+ * Send funds to a test account, adding the max of 2 * stakeAmount or 100 * the
18
+ * existential deposit
19
+ * @param env
20
+ * @param stakeAmount
21
+ */
22
+ export declare function getSendAmount(env: ProsopoEnvironment, stakeAmount: BN): BN;
23
+ //# sourceMappingURL=funds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"funds.d.ts","sourceRoot":"","sources":["../../src/setup/funds.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AACvD,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AAGnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAgBvD,0EAA0E;AAC1E,wBAAsB,SAAS,CAC3B,GAAG,EAAE,kBAAkB,EACvB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,GAClB,OAAO,CAAC,IAAI,CAAC,CAgEf;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,EAAE,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,EAAE,CAgB9G;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,kBAAkB,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,CAS1E"}
@@ -0,0 +1,102 @@
1
+ import { BN } from '@polkadot/util';
2
+ import { ProsopoEnvError } from '@prosopo/common';
3
+ import { at } from '@prosopo/util';
4
+ import { dispatchErrorHandler, oneUnit } from '@prosopo/contract';
5
+ const devMnemonics = ['//Alice', '//Bob', '//Charlie', '//Dave', '//Eve', '//Ferdie'];
6
+ let current = -1;
7
+ const MAX_ACCOUNT_FUND = 10000; // 10000 UNIT
8
+ /** Cycle through the dev mnemonics so as not to deplete the funds too quickly
9
+ */
10
+ function getNextMnemonic() {
11
+ current = (current + 1) % devMnemonics.length;
12
+ return at(devMnemonics, current);
13
+ }
14
+ /** Send funds from one of the development accounts to another account. */
15
+ export async function sendFunds(env, address, who, amount) {
16
+ const envApi = env.getApi();
17
+ await envApi.isReady;
18
+ const mnemonic = getNextMnemonic();
19
+ const pair = env.keyring.addFromMnemonic(mnemonic);
20
+ const nonce = await envApi.rpc.system.accountNextIndex(pair.address);
21
+ const { data: { free: previousFree }, } = await env.getContractInterface().api.query.system.account(pair.address);
22
+ if (previousFree.lt(new BN(amount.toString()))) {
23
+ throw new ProsopoEnvError('DEVELOPER.BALANCE_TOO_LOW', undefined, undefined, {
24
+ mnemonic,
25
+ previousFree: previousFree.toString(),
26
+ amount: amount.toString(),
27
+ });
28
+ }
29
+ const api = env.getContractInterface().api;
30
+ const unit = oneUnit(envApi);
31
+ const unitAmount = new BN(amount.toString()).div(unit).toString();
32
+ env.logger.debug('Sending funds from', pair.address, 'to', address, 'Amount:', unitAmount, 'UNIT. Free balance:', previousFree.div(unit).toString(), 'UNIT');
33
+ // eslint-disable-next-line no-async-promise-executor
34
+ const result = new Promise(async (resolve, reject) => {
35
+ const unsub = await api.tx.balances
36
+ .transfer(address, amount)
37
+ .signAndSend(pair, { nonce }, (result) => {
38
+ if (result.status.isInBlock || result.status.isFinalized) {
39
+ result.events
40
+ .filter(({ event: { section } }) => section === 'system')
41
+ .forEach((event) => {
42
+ const { event: { method }, } = event;
43
+ if (method === 'ExtrinsicFailed') {
44
+ unsub();
45
+ reject(dispatchErrorHandler(api.registry, event));
46
+ }
47
+ });
48
+ unsub();
49
+ resolve(result);
50
+ }
51
+ else if (result.isError) {
52
+ unsub();
53
+ reject(result);
54
+ }
55
+ });
56
+ });
57
+ await result
58
+ .then((result) => {
59
+ env.logger.debug(who, 'sent amount', unitAmount, 'UNIT at tx hash ', result.status.asInBlock.toHex());
60
+ })
61
+ .catch((e) => {
62
+ throw new ProsopoEnvError('DEVELOPER.FUNDING_FAILED', undefined, undefined, { e });
63
+ });
64
+ }
65
+ /**
66
+ * Takes the providerStakeDefault and works out if multiplying it by 100 or
67
+ * stakeMultiplier is greater than the maxStake. If it is, it returns the maxStake
68
+ * If chain decimals = 12, 1 UNIT = 1e12
69
+ * @param env
70
+ * @param providerStakeDefault
71
+ * @param stakeMultiplier
72
+ */
73
+ export function getStakeAmount(env, providerStakeDefault, stakeMultiplier) {
74
+ const unit = oneUnit(env.getApi());
75
+ // We want to give each provider 100 * the required stake or 1 UNIT, whichever is greater, so that gas fees can be
76
+ // refunded to the Dapp User from within the contract
77
+ const stake100 = BN.max(providerStakeDefault.muln(stakeMultiplier || 100), unit);
78
+ // We don't want to stake any more than MAX_ACCOUNT_FUND UNIT per provider as the test account funds will be depleted too quickly
79
+ const maxStake = unit.muln(MAX_ACCOUNT_FUND);
80
+ if (stake100.lt(maxStake)) {
81
+ env.logger.debug('Setting stake amount to', stake100.div(unit).toNumber(), 'UNIT');
82
+ return stake100;
83
+ }
84
+ env.logger.debug('Setting stake amount to', maxStake.div(unit).toNumber(), 'UNIT');
85
+ return maxStake;
86
+ }
87
+ /**
88
+ * Send funds to a test account, adding the max of 2 * stakeAmount or 100 * the
89
+ * existential deposit
90
+ * @param env
91
+ * @param stakeAmount
92
+ */
93
+ export function getSendAmount(env, stakeAmount) {
94
+ const unit = oneUnit(env.getApi());
95
+ env.logger.debug('Stake amount', stakeAmount.div(unit).toNumber(), 'UNIT');
96
+ let sendAmount = new BN(stakeAmount).muln(2);
97
+ // Should result in each account receiving a minimum of existentialDeposit
98
+ sendAmount = BN.max(sendAmount, env.getApi().consts.balances.existentialDeposit.muln(100));
99
+ env.logger.debug('Setting send amount to', sendAmount.div(unit).toNumber(), 'UNIT');
100
+ return sendAmount;
101
+ }
102
+ //# sourceMappingURL=funds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"funds.js","sourceRoot":"","sources":["../../src/setup/funds.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAA;AAClC,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEjE,MAAM,YAAY,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC,CAAA;AACrF,IAAI,OAAO,GAAG,CAAC,CAAC,CAAA;AAChB,MAAM,gBAAgB,GAAG,KAAK,CAAA,CAAC,aAAa;AAE5C;GACG;AACH,SAAS,eAAe;IACpB,OAAO,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,GAAG,YAAY,CAAC,MAAM,CAAA;IAE7C,OAAO,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;AACpC,CAAC;AAED,0EAA0E;AAC1E,MAAM,CAAC,KAAK,UAAU,SAAS,CAC3B,GAAuB,EACvB,OAAe,EACf,GAAW,EACX,MAAiB;IAEjB,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAA;IAC3B,MAAM,MAAM,CAAC,OAAO,CAAA;IACpB,MAAM,QAAQ,GAAG,eAAe,EAAE,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AC,CAAC,CAAC,CAAA;IAE5C,0EAA0E;IAC1E,UAAU,GAAG,EAAE,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IAC1F,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,CAAA;IACnF,OAAO,UAAU,CAAA;AACrB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './setup.js';
2
+ export * from './provider.js';
3
+ export * from './dapp.js';
4
+ export * from './funds.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/setup/index.ts"],"names":[],"mappings":"AAaA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA"}
@@ -0,0 +1,18 @@
1
+ // Copyright 2021-2023 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ export * from './setup.js';
15
+ export * from './provider.js';
16
+ export * from './dapp.js';
17
+ export * from './funds.js';
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/setup/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { IProviderAccount } from '@prosopo/types';
2
+ import { ProviderEnvironment } from '@prosopo/types-env';
3
+ export declare function registerProvider(env: ProviderEnvironment, account: IProviderAccount, force?: boolean): Promise<void>;
4
+ export declare function setupProvider(env: ProviderEnvironment, provider: IProviderAccount): Promise<void>;
5
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/setup/provider.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAGjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAQxD,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,mBAAmB,EAAE,OAAO,EAAE,gBAAgB,EAAE,KAAK,CAAC,EAAE,OAAO,iBAgC1G;AAED,wBAAsB,aAAa,CAAC,GAAG,EAAE,mBAAmB,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmDvG"}
@@ -0,0 +1,84 @@
1
+ import { ProsopoEnvError } from '@prosopo/common';
2
+ import { Tasks } from '@prosopo/provider';
3
+ import { getSendAmount, getStakeAmount, sendFunds } from './funds.js';
4
+ import { loadJSONFile } from '@prosopo/cli';
5
+ import { stringToU8a } from '@polkadot/util';
6
+ import { wrapQuery } from '@prosopo/contract';
7
+ export async function registerProvider(env, account, force) {
8
+ try {
9
+ const provider = (await env.getContractInterface().query.getProvider(account.address)).value.unwrap().unwrap();
10
+ if (provider.status.toString() === 'Active' && !force) {
11
+ env.logger.info('Provider exists and is active, skipping registration.');
12
+ return;
13
+ }
14
+ }
15
+ catch {
16
+ env.logger.info('Provider does not exist, registering...');
17
+ }
18
+ if (account.secret) {
19
+ const providerKeyringPair = env.keyring.addFromMnemonic(account.secret);
20
+ account.address = providerKeyringPair.address;
21
+ const result = await wrapQuery(env.getContractInterface().query.getProviderStakeThreshold, env.getContractInterface().query)();
22
+ const stakeAmount = result.rawNumber;
23
+ // use the minimum stake amount from the contract to create a reasonable stake amount
24
+ account.stake = getStakeAmount(env, stakeAmount);
25
+ const sendAmount = getSendAmount(env, account.stake);
26
+ // send enough funds to cover the stake amount and more
27
+ await sendFunds(env, account.address, 'Provider', sendAmount);
28
+ await setupProvider(env, account);
29
+ }
30
+ else {
31
+ throw new ProsopoEnvError('GENERAL.NO_MNEMONIC_OR_SEED');
32
+ }
33
+ }
34
+ export async function setupProvider(env, provider) {
35
+ if (!provider.pair) {
36
+ throw new ProsopoEnvError('DEVELOPER.MISSING_PROVIDER_PAIR', undefined, undefined, { provider });
37
+ }
38
+ await env.changeSigner(provider.pair);
39
+ const logger = env.logger;
40
+ const tasks = new Tasks(env);
41
+ logger.info(' - providerRegister');
42
+ const providerRegisterArgs = [
43
+ Array.from(stringToU8a(provider.url)),
44
+ provider.fee,
45
+ provider.payee,
46
+ {
47
+ value: 0,
48
+ },
49
+ ];
50
+ let providerExists = false;
51
+ try {
52
+ await wrapQuery(tasks.contract.query.providerRegister, tasks.contract.query)(...providerRegisterArgs);
53
+ }
54
+ catch (e) {
55
+ if (e === 'ProviderExists') {
56
+ logger.info('Provider already exists');
57
+ providerExists = true;
58
+ }
59
+ else {
60
+ throw e;
61
+ }
62
+ }
63
+ if (!providerExists) {
64
+ await tasks.contract.tx.providerRegister(...providerRegisterArgs);
65
+ }
66
+ const registeredProvider = await wrapQuery(tasks.contract.query.getProvider, tasks.contract.query)(provider.address);
67
+ logger.info(registeredProvider);
68
+ logger.info(' - providerStake');
69
+ const providerUpdateArgs = [
70
+ Array.from(stringToU8a(provider.url)),
71
+ provider.fee,
72
+ provider.payee,
73
+ {
74
+ value: provider.stake,
75
+ },
76
+ ];
77
+ // Do this to catch any errors before running the tx
78
+ await wrapQuery(tasks.contract.query.providerUpdate, tasks.contract.query)(...providerUpdateArgs);
79
+ await tasks.contract.tx.providerUpdate(...providerUpdateArgs);
80
+ logger.info(' - providerSetDataset');
81
+ const datasetJSON = loadJSONFile(provider.datasetFile);
82
+ await tasks.providerSetDatasetFromFile(datasetJSON);
83
+ }
84
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/setup/provider.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAGjD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,GAAwB,EAAE,OAAyB,EAAE,KAAe;IACvG,IAAI;QACA,MAAM,QAAQ,GAAG,CAAC,MAAM,GAAG,CAAC,oBAAoB,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAA;QAC9G,IAAI,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,QAAQ,IAAI,CAAC,KAAK,EAAE;YACnD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAA;YACxE,OAAM;SACT;KACJ;IAAC,MAAM;QACJ,GAAG,CA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SACxB;KACJ,CAAA;IAED,oDAAoD;IACpD,MAAM,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAA;IAEjG,MAAM,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAC,CAAA;IAE7D,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAA;IACtC,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;IACtD,MAAM,KAAK,CAAC,0BAA0B,CAAC,WAAW,CAAC,CAAA;AACvD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function setup(force: boolean): Promise<void>;
2
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/setup/setup.ts"],"names":[],"mappings":"AAuGA,wBAAsB,KAAK,CAAC,KAAK,EAAE,OAAO,iBAmEzC"}
@@ -0,0 +1,151 @@
1
+ // Copyright 2021-2023 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { ArgumentTypes } from '@prosopo/types';
15
+ import { BN } from '@polkadot/util';
16
+ import { LogLevel, ProsopoEnvError, getLogger, getPair } from '@prosopo/common';
17
+ import { ProviderEnvironment } from '@prosopo/env';
18
+ import { defaultConfig, getPairType, getSecret, getSs58Format } from '@prosopo/cli';
19
+ import { generateMnemonic, wrapQuery } from '@prosopo/contract';
20
+ import { get } from '@prosopo/util';
21
+ import { getEnvFile } from '@prosopo/cli';
22
+ import { registerProvider } from './provider.js';
23
+ import { setupDapp } from './dapp.js';
24
+ import fse from 'fs-extra';
25
+ import path from 'path';
26
+ const logger = getLogger(LogLevel.enum.info, 'setup');
27
+ const __dirname = path.resolve();
28
+ // Take the root dir from the environment or assume it's the root of this package
29
+ function getRootDir() {
30
+ const rootDir = process.env.ROOT_DIR || path.resolve(__dirname, '../..');
31
+ logger.info('Root dir:', rootDir);
32
+ return rootDir;
33
+ }
34
+ function getDatasetFilePath() {
35
+ const datasetFile = process.env.PROVIDER_DATASET_FILE || path.resolve('../data/captchas.json');
36
+ logger.info('Dataset file:', datasetFile);
37
+ return datasetFile;
38
+ }
39
+ function getDefaultProvider() {
40
+ return {
41
+ url: process.env.API_PORT ? `http://localhost:${process.env.API_PORT}` : 'http://localhost:3000',
42
+ fee: 10,
43
+ payee: ArgumentTypes.Payee.dapp,
44
+ stake: Math.pow(10, 13),
45
+ datasetFile: getDatasetFilePath(),
46
+ address: process.env.PROVIDER_ADDRESS || '',
47
+ secret: getSecret(),
48
+ captchaDatasetId: '',
49
+ };
50
+ }
51
+ function getDefaultDapp() {
52
+ return {
53
+ secret: '//Eve',
54
+ contractAccount: process.env.DAPP_SITE_KEY || '',
55
+ fundAmount: Math.pow(10, 12),
56
+ };
57
+ }
58
+ async function copyEnvFile() {
59
+ try {
60
+ const rootDir = getRootDir();
61
+ // TODO move all env files to a single template location
62
+ const tplLocation = path.resolve(rootDir, './dev/scripts');
63
+ const tplEnvFile = getEnvFile(tplLocation, 'env');
64
+ const envFile = getEnvFile(tplLocation, '.env');
65
+ await fse.copy(tplEnvFile, envFile, { overwrite: false });
66
+ }
67
+ catch (err) {
68
+ logger.debug(err);
69
+ }
70
+ }
71
+ function updateEnvFileVar(source, name, value) {
72
+ const envVar = new RegExp(`.*(${name}=)(.*)`, 'g');
73
+ if (envVar.test(source)) {
74
+ return source.replace(envVar, `$1${value}`);
75
+ }
76
+ return source + `\n${name}=${value}`;
77
+ }
78
+ async function updateEnvFile(vars) {
79
+ const rootDir = getRootDir();
80
+ const envFile = getEnvFile(rootDir, '.env');
81
+ let readEnvFile = await fse.readFile(envFile, 'utf8');
82
+ for (const key in vars) {
83
+ readEnvFile = updateEnvFileVar(readEnvFile, key, get(vars, key));
84
+ }
85
+ await fse.writeFile(envFile, readEnvFile);
86
+ }
87
+ async function registerDapp(env, dapp) {
88
+ await setupDapp(env, dapp);
89
+ }
90
+ export async function setup(force) {
91
+ const defaultProvider = getDefaultProvider();
92
+ const defaultDapp = getDefaultDapp();
93
+ if (defaultProvider.secret) {
94
+ const hasProviderAccount = defaultProvider.address && defaultProvider.secret;
95
+ logger.debug('ENVIRONMENT', process.env.NODE_ENV);
96
+ const [mnemonic, address] = !hasProviderAccount
97
+ ? await generateMnemonic()
98
+ : [defaultProvider.secret, defaultProvider.address];
99
+ logger.debug(`Address: ${address}`);
100
+ logger.debug(`Mnemonic: ${mnemonic}`);
101
+ logger.debug('Writing .env file...');
102
+ await copyEnvFile();
103
+ if (!process.env.DAPP_SITE_KEY) {
104
+ throw new ProsopoEnvError('DEVELOPER.DAPP_SITE_KEY_MISSING');
105
+ }
106
+ const pairType = getPairType();
107
+ const ss58Format = getSs58Format();
108
+ const secret = '//Alice';
109
+ const pair = await getPair(pairType, ss58Format, secret);
110
+ const env = new ProviderEnvironment(pair, defaultConfig());
111
+ await env.isReady();
112
+ const result = await wrapQuery(env.getContractInterface().query.getDappStakeThreshold, env.getContractInterface().query)();
113
+ const stakeAmount = result.rawNumber;
114
+ let fundAmount = new BN(0);
115
+ if (typeof defaultDapp.fundAmount === 'number') {
116
+ fundAmount = new BN(defaultDapp.fundAmount);
117
+ }
118
+ else {
119
+ fundAmount = defaultDapp.fundAmount;
120
+ }
121
+ defaultDapp.fundAmount = BN.max(stakeAmount, fundAmount);
122
+ defaultProvider.secret = mnemonic;
123
+ env.logger.info(`Registering provider... ${defaultProvider.address}`);
124
+ defaultProvider.pair = await getPair(pairType, ss58Format, mnemonic);
125
+ await registerProvider(env, defaultProvider, force);
126
+ defaultDapp.contractAccount = process.env.DAPP_SITE_KEY;
127
+ defaultDapp.pair = await getPair(pairType, ss58Format, defaultDapp.secret);
128
+ env.logger.info('Registering dapp...');
129
+ await registerDapp(env, defaultDapp);
130
+ if (!hasProviderAccount) {
131
+ await updateEnvFile({
132
+ PROVIDER_MNEMONIC: `"${mnemonic}"`,
133
+ PROVIDER_ADDRESS: address,
134
+ });
135
+ }
136
+ process.exit();
137
+ }
138
+ else {
139
+ console.error('no secret found in .env file');
140
+ throw new ProsopoEnvError(`GENERAL.NO_MNEMONIC_OR_SEED`);
141
+ }
142
+ }
143
+ //if main process
144
+ // if (typeof require !== 'undefined' && require.main === module) {
145
+ // console.info('Running setup as main process')
146
+ //
147
+ // setup()
148
+ // .then((r) => logger.debug('Setup done'))
149
+ // .catch((e) => console.error(e))
150
+ // }
151
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/setup/setup.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AAEnC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAElD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACnF,O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AO,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAA;QAEpE,MAAM,gBAAgB,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,CAAC,CAAA;QAEnD,WAAW,CAAC,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAA;QAEvD,WAAW,CAAC,IAAI,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;QAE1E,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;QACtC,MAAM,YAAY,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;QAEpC,IAAI,CAAC,kBAAkB,EAAE;YACrB,MAAM,aAAa,CAAC;gBAChB,iBAAiB,EAAE,IAAI,QAAQ,GAAG;gBAClC,gBAAgB,EAAE,OAAO;aAC5B,CAAC,CAAA;SACL;QACD,OAAO,CAAC,IAAI,EAAE,CAAA;KACjB;SAAM;QACH,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAA;QAC7C,MAAM,IAAI,eAAe,CAAC,6BAA6B,CAAC,CAAA;KAC3D;AACL,CAAC;AAED,iBAAiB;AACjB,mEAAmE;AACnE,oDAAoD;AACpD,EAAE;AACF,cAAc;AACd,mDAAmD;AACnD,0CAA0C;AAC1C,IAAI"}
@@ -0,0 +1,10 @@
1
+ export interface ExecOutput {
2
+ stdout: string;
3
+ stderr: string;
4
+ code: number | null;
5
+ }
6
+ export declare const exec: (command: string, options?: {
7
+ pipe?: boolean;
8
+ printCmd?: boolean;
9
+ }) => Promise<ExecOutput>;
10
+ //# sourceMappingURL=exec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../src/util/exec.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CACtB;AAED,eAAO,MAAM,IAAI,YACJ,MAAM,YACL;IACN,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;CACrB,KACF,QAAQ,UAAU,CA6CpB,CAAA"}