@ocap/resolver 1.20.2 → 1.20.4
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.
- package/README.md +1 -1
- package/lib/index.js +44 -35
- package/package.json +23 -20
package/README.md
CHANGED
package/lib/index.js
CHANGED
|
@@ -818,52 +818,61 @@ module.exports = class OCAPResolver {
|
|
|
818
818
|
// Auto persist config to chain state
|
|
819
819
|
// Will throw error if immutable chain config are updated
|
|
820
820
|
const info = await this.getChain();
|
|
821
|
-
await this.runAsLambda(
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
821
|
+
await this.runAsLambda(
|
|
822
|
+
async (txn) => {
|
|
823
|
+
if (!info) {
|
|
824
|
+
const state = chainState.create({ ...this.config, address: CHAIN_ADDR }, context);
|
|
825
|
+
const result = await chainDB.create(CHAIN_ADDR, state, { txn });
|
|
826
|
+
this.logger.debug('create chain state', { result });
|
|
827
|
+
} else if (isEqual(pick(info, Object.keys(this.config)), this.config) === false) {
|
|
828
|
+
const state = chainState.update(info, this.config, context);
|
|
829
|
+
const result = await chainDB.update(CHAIN_ADDR, state, { txn });
|
|
830
|
+
this.logger.debug('update chain state', { result });
|
|
831
|
+
}
|
|
832
|
+
},
|
|
833
|
+
{ commitMessage: 'initialize chain' }
|
|
834
|
+
);
|
|
832
835
|
|
|
833
836
|
// Auto persist token state, just once
|
|
834
837
|
// Since the token info should not be changed after restart
|
|
835
838
|
if (this.tokenItx) {
|
|
836
839
|
const existToken = await this.getToken(this.tokenItx.address);
|
|
837
840
|
if (!existToken) {
|
|
838
|
-
await this.runAsLambda(
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
841
|
+
await this.runAsLambda(
|
|
842
|
+
async (txn) => {
|
|
843
|
+
const state = tokenState.create(this.tokenItx, context);
|
|
844
|
+
const result = await tokenDB.create(this.tokenItx.address, state, { txn });
|
|
845
|
+
tokenDB.emit('create', result, { txn });
|
|
846
|
+
this.logger.debug('create token state', { address: result?.address });
|
|
847
|
+
},
|
|
848
|
+
{ commitMessage: 'initialize token' }
|
|
849
|
+
);
|
|
844
850
|
}
|
|
845
851
|
|
|
846
852
|
// Auto populate token holder accounts if not exist
|
|
847
|
-
await this.runAsLambda(
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
853
|
+
await this.runAsLambda(
|
|
854
|
+
async (txn) => {
|
|
855
|
+
for (let i = 0; i < accounts.length; i++) {
|
|
856
|
+
const { address, balance, moniker, pk } = accounts[i];
|
|
857
|
+
try {
|
|
858
|
+
const existAccount = await accountDB.get(address, { txn });
|
|
859
|
+
if (!existAccount) {
|
|
860
|
+
const balanceStr = fromTokenToUnit(balance, token.decimal).toString(10);
|
|
861
|
+
const state = accountState.create(
|
|
862
|
+
{ address, tokens: { [this.tokenItx.address]: balanceStr }, moniker: moniker || 'token-holder', pk },
|
|
863
|
+
context
|
|
864
|
+
);
|
|
865
|
+
const result = await accountDB.create(address, state, { txn });
|
|
866
|
+
accountDB.emit('create', result, { txn });
|
|
867
|
+
this.logger.debug('create account done', { address });
|
|
868
|
+
}
|
|
869
|
+
} catch (err) {
|
|
870
|
+
this.logger.error('Failed to initialize initial token holders', err);
|
|
861
871
|
}
|
|
862
|
-
} catch (err) {
|
|
863
|
-
this.logger.error('Failed to initialize initial token holders', err);
|
|
864
872
|
}
|
|
865
|
-
}
|
|
866
|
-
|
|
873
|
+
},
|
|
874
|
+
{ commitMessage: 'initialize accounts' }
|
|
875
|
+
);
|
|
867
876
|
}
|
|
868
877
|
}
|
|
869
878
|
|
package/package.json
CHANGED
|
@@ -3,18 +3,12 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.20.
|
|
6
|
+
"version": "1.20.4",
|
|
7
7
|
"description": "GraphQL resolver built upon ocap statedb and GQL layer",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
10
10
|
"lib"
|
|
11
11
|
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"lint": "eslint tests lib",
|
|
14
|
-
"lint:fix": "eslint --fix tests lib",
|
|
15
|
-
"test": "jest --forceExit --detectOpenHandles",
|
|
16
|
-
"coverage": "npm run test -- --coverage"
|
|
17
|
-
},
|
|
18
12
|
"keywords": [],
|
|
19
13
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
14
|
"license": "MIT",
|
|
@@ -22,19 +16,28 @@
|
|
|
22
16
|
"jest": "^29.7.0"
|
|
23
17
|
},
|
|
24
18
|
"dependencies": {
|
|
25
|
-
"@arcblock/did": "1.20.2",
|
|
26
|
-
"@arcblock/did-util": "1.20.2",
|
|
27
|
-
"@arcblock/validator": "1.20.2",
|
|
28
|
-
"@ocap/config": "1.20.2",
|
|
29
|
-
"@ocap/indexdb": "1.20.2",
|
|
30
|
-
"@ocap/mcrypto": "1.20.2",
|
|
31
|
-
"@ocap/message": "1.20.2",
|
|
32
|
-
"@ocap/state": "1.20.2",
|
|
33
|
-
"@ocap/tx-protocols": "1.20.2",
|
|
34
|
-
"@ocap/util": "1.20.2",
|
|
35
19
|
"debug": "^4.3.6",
|
|
36
20
|
"lodash": "^4.17.21",
|
|
37
|
-
"queue": "^6"
|
|
21
|
+
"queue": "^6",
|
|
22
|
+
"@arcblock/did": "1.20.4",
|
|
23
|
+
"@arcblock/did-util": "1.20.4",
|
|
24
|
+
"@arcblock/validator": "1.20.4",
|
|
25
|
+
"@ocap/config": "1.20.4",
|
|
26
|
+
"@ocap/indexdb": "1.20.4",
|
|
27
|
+
"@ocap/message": "1.20.4",
|
|
28
|
+
"@ocap/state": "1.20.4",
|
|
29
|
+
"@ocap/tx-protocols": "1.20.4",
|
|
30
|
+
"@ocap/util": "1.20.4",
|
|
31
|
+
"@ocap/wallet": "1.20.4",
|
|
32
|
+
"@ocap/statedb-memory": "1.20.4",
|
|
33
|
+
"@arcblock/did-ext": "1.20.4",
|
|
34
|
+
"@ocap/mcrypto": "1.20.4",
|
|
35
|
+
"@ocap/indexdb-memory": "1.20.4"
|
|
38
36
|
},
|
|
39
|
-
"
|
|
40
|
-
|
|
37
|
+
"scripts": {
|
|
38
|
+
"lint": "eslint tests lib",
|
|
39
|
+
"lint:fix": "eslint --fix tests lib",
|
|
40
|
+
"test": "jest --forceExit --detectOpenHandles",
|
|
41
|
+
"coverage": "npm run test -- --coverage"
|
|
42
|
+
}
|
|
43
|
+
}
|