@wishknish/knishio-client-js 0.4.41 → 0.4.44
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/dist/client.umd.js +24 -24
- package/package.json +31 -32
- package/src/Atom.js +5 -0
- package/src/KnishIOClient.js +107 -11
- package/src/Molecule.js +115 -66
- package/src/httpClient/ApolloClient.js +0 -1
- package/src/instance/Rules/Callback.js +119 -0
- package/src/instance/Rules/Meta.js +84 -0
- package/src/instance/Rules/Rule.js +134 -0
- package/src/instance/Rules/exception/RuleArgumentException.js +15 -0
- package/src/libraries/ApolloLink/AuthLink.js +1 -3
- package/src/libraries/ApolloLink/CipherLink.js +1 -3
- package/src/libraries/ApolloLink/EchoLink.js +1 -3
- package/src/libraries/ApolloLink/HttpLink.js +0 -2
- package/src/libraries/ApolloLink/handler.js +1 -4
- package/src/libraries/check.js +10 -14
- package/src/mutation/Mutation.js +0 -1
- package/src/mutation/MutationCreateRule.js +91 -0
- package/src/query/Query.js +0 -1
- package/src/response/ResponseCreateRule.js +55 -0
- package/src/subscribe/Subscribe.js +0 -1
- package/src/test/Test.js +32 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wishknish/knishio-client-js",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.44",
|
|
4
4
|
"productName": "Knish.IO Javascript SDK Client",
|
|
5
5
|
"description": "JavaScript implementation of the Knish.IO SDK to consume Knish.IO GraphQL APIs.",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"base-x": "^3.0.8",
|
|
46
46
|
"big-integer": "^1.6.48",
|
|
47
47
|
"buffer": "^6.0.3",
|
|
48
|
+
"core-js": "3.21.1",
|
|
48
49
|
"get-random-values": "^1.2.2",
|
|
49
50
|
"graphql": "^15.5.0",
|
|
50
51
|
"isomorphic-fetch": "^3.0.0",
|
|
@@ -58,50 +59,48 @@
|
|
|
58
59
|
"/src"
|
|
59
60
|
],
|
|
60
61
|
"devDependencies": {
|
|
61
|
-
"@babel/core": "^7.
|
|
62
|
-
"@babel/
|
|
63
|
-
"@babel/plugin
|
|
64
|
-
"@babel/plugin-
|
|
65
|
-
"@babel/plugin-proposal-
|
|
66
|
-
"@babel/plugin-proposal-
|
|
67
|
-
"@babel/plugin-proposal-
|
|
68
|
-
"@babel/plugin-proposal-
|
|
69
|
-
"@babel/plugin-proposal-
|
|
70
|
-
"@babel/plugin-proposal-
|
|
71
|
-
"@babel/plugin-proposal-
|
|
72
|
-
"@babel/plugin-proposal-
|
|
73
|
-
"@babel/plugin-proposal-
|
|
74
|
-
"@babel/plugin-proposal-
|
|
75
|
-
"@babel/plugin-proposal-
|
|
76
|
-
"@babel/plugin-proposal-
|
|
62
|
+
"@babel/core": "^7.17.8",
|
|
63
|
+
"@babel/eslint-parser": "^7.17.0",
|
|
64
|
+
"@babel/eslint-plugin": "^7.17.7",
|
|
65
|
+
"@babel/plugin-external-helpers": "^7.16.7",
|
|
66
|
+
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
67
|
+
"@babel/plugin-proposal-decorators": "^7.17.8",
|
|
68
|
+
"@babel/plugin-proposal-do-expressions": "^7.16.7",
|
|
69
|
+
"@babel/plugin-proposal-export-default-from": "^7.16.7",
|
|
70
|
+
"@babel/plugin-proposal-export-namespace-from": "^7.16.7",
|
|
71
|
+
"@babel/plugin-proposal-function-bind": "^7.16.7",
|
|
72
|
+
"@babel/plugin-proposal-function-sent": "^7.16.7",
|
|
73
|
+
"@babel/plugin-proposal-json-strings": "^7.16.7",
|
|
74
|
+
"@babel/plugin-proposal-logical-assignment-operators": "^7.16.7",
|
|
75
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
|
|
76
|
+
"@babel/plugin-proposal-numeric-separator": "^7.16.7",
|
|
77
|
+
"@babel/plugin-proposal-optional-chaining": "^7.16.7",
|
|
78
|
+
"@babel/plugin-proposal-pipeline-operator": "^7.17.6",
|
|
79
|
+
"@babel/plugin-proposal-throw-expressions": "^7.16.7",
|
|
77
80
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
78
|
-
"@babel/plugin-syntax-import-meta": "^7.
|
|
79
|
-
"@babel/plugin-transform-arrow-functions": "^7.
|
|
80
|
-
"@babel/plugin-transform-async-to-generator": "^7.
|
|
81
|
-
"@babel/plugin-transform-classes": "^7.
|
|
82
|
-
"@babel/plugin-transform-for-of": "^7.
|
|
83
|
-
"@babel/plugin-transform-property-mutators": "^7.
|
|
81
|
+
"@babel/plugin-syntax-import-meta": "^7.10.4",
|
|
82
|
+
"@babel/plugin-transform-arrow-functions": "^7.16.7",
|
|
83
|
+
"@babel/plugin-transform-async-to-generator": "^7.16.8",
|
|
84
|
+
"@babel/plugin-transform-classes": "^7.16.7",
|
|
85
|
+
"@babel/plugin-transform-for-of": "^7.16.7",
|
|
86
|
+
"@babel/plugin-transform-property-mutators": "^7.16.7",
|
|
84
87
|
"@babel/plugin-transform-runtime": "^7.12.15",
|
|
85
88
|
"@babel/plugin-transform-shorthand-properties": "^7.12.13",
|
|
86
|
-
"@babel/polyfill": "^7.12.1",
|
|
87
89
|
"@babel/preset-env": "^7.12.13",
|
|
88
90
|
"@babel/runtime": "^7.12.13",
|
|
89
91
|
"@rollup/plugin-babel": "^5.2.3",
|
|
90
92
|
"@rollup/plugin-commonjs": "^19.0.0",
|
|
93
|
+
"@rollup/plugin-inject": "^4.0.4",
|
|
91
94
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
92
|
-
"
|
|
95
|
+
"@rollup/plugin-replace": "^4.0.0",
|
|
93
96
|
"babel-loader": "^8.2.2",
|
|
94
|
-
"babel-preset-es2015-rollup": "^3.0.0",
|
|
95
97
|
"eslint": "^7.23.0",
|
|
96
98
|
"eslint-plugin-vue": "^7.8.0",
|
|
97
|
-
"nodemon": "^2.0.
|
|
98
|
-
"rollup": "^2.
|
|
99
|
-
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
99
|
+
"nodemon": "^2.0.15",
|
|
100
|
+
"rollup": "^2.70.1",
|
|
100
101
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
101
|
-
"rollup-plugin-replace": "^2.2.0",
|
|
102
102
|
"rollup-plugin-terser": "^7.0.2",
|
|
103
|
-
"
|
|
104
|
-
"uglify-es": "^3.3.9",
|
|
103
|
+
"uglify-js": "^3.15.3",
|
|
105
104
|
"webpack": "^5.21.1",
|
|
106
105
|
"webpack-cli": "^4.5.0",
|
|
107
106
|
"webpack-merge": "^5.7.3"
|
package/src/Atom.js
CHANGED
|
@@ -319,6 +319,11 @@ export default class Atom {
|
|
|
319
319
|
continue;
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
+
// Excluded keys
|
|
323
|
+
if ( [ 'otsFragment', 'index' ].includes( property ) ) {
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
|
|
322
327
|
// Hashing individual meta keys and values
|
|
323
328
|
if ( property === 'meta' ) {
|
|
324
329
|
for ( const meta of value ) {
|
package/src/KnishIOClient.js
CHANGED
|
@@ -93,6 +93,7 @@ import QueryAtom from './query/QueryAtom';
|
|
|
93
93
|
import QueryPolicy from './query/QueryPolicy';
|
|
94
94
|
import MutationCreatePolicy from './mutation/MutationCreatePolicy';
|
|
95
95
|
import QueryMetaTypeViaAtom from './query/QueryMetaTypeViaAtom';
|
|
96
|
+
import MutationCreateRule from './mutation/MutationCreateRule';
|
|
96
97
|
|
|
97
98
|
|
|
98
99
|
/**
|
|
@@ -460,30 +461,29 @@ export default class KnishIOClient {
|
|
|
460
461
|
console.info( 'KnishIOClient::createMolecule() - Creating a new molecule...' );
|
|
461
462
|
}
|
|
462
463
|
|
|
463
|
-
|
|
464
|
-
let _sourceWallet = sourceWallet;
|
|
464
|
+
secret = secret || this.getSecret();
|
|
465
465
|
|
|
466
466
|
// Sets the source wallet as the last remainder wallet (to maintain ContinuID)
|
|
467
|
-
if ( !sourceWallet && this.lastMoleculeQuery && this.getRemainderWallet().token !== 'AUTH' && this.lastMoleculeQuery
|
|
468
|
-
|
|
467
|
+
if ( !sourceWallet && this.lastMoleculeQuery && this.getRemainderWallet().token !== 'AUTH' && this.lastMoleculeQuery.response() && this.lastMoleculeQuery.response().success() ) {
|
|
468
|
+
sourceWallet = this.getRemainderWallet();
|
|
469
469
|
}
|
|
470
470
|
|
|
471
471
|
// Unable to use last remainder wallet; Figure out what wallet to use:
|
|
472
|
-
if (
|
|
473
|
-
|
|
472
|
+
if ( sourceWallet === null ) {
|
|
473
|
+
sourceWallet = await this.getSourceWallet();
|
|
474
474
|
}
|
|
475
475
|
|
|
476
476
|
// Set the remainder wallet for the next transaction
|
|
477
477
|
this.remainderWallet = remainderWallet || Wallet.create( {
|
|
478
|
-
secretOrBundle:
|
|
478
|
+
secretOrBundle: secret,
|
|
479
479
|
token: 'USER',
|
|
480
|
-
batchId:
|
|
481
|
-
characters:
|
|
480
|
+
batchId: sourceWallet.batchId,
|
|
481
|
+
characters: sourceWallet.characters
|
|
482
482
|
} );
|
|
483
483
|
|
|
484
484
|
return new Molecule( {
|
|
485
|
-
secret
|
|
486
|
-
sourceWallet
|
|
485
|
+
secret,
|
|
486
|
+
sourceWallet,
|
|
487
487
|
remainderWallet: this.getRemainderWallet(),
|
|
488
488
|
cellSlug: this.cellSlug()
|
|
489
489
|
} );
|
|
@@ -1178,6 +1178,42 @@ export default class KnishIOClient {
|
|
|
1178
1178
|
return await this.executeQuery( query );
|
|
1179
1179
|
}
|
|
1180
1180
|
|
|
1181
|
+
/**
|
|
1182
|
+
*
|
|
1183
|
+
* @param {string} metaType
|
|
1184
|
+
* @param {string} metaId
|
|
1185
|
+
* @param {object[]} rule
|
|
1186
|
+
* @param {object} policy
|
|
1187
|
+
* @returns {Promise<ResponseCreateRule>}
|
|
1188
|
+
*/
|
|
1189
|
+
async createRule ( {
|
|
1190
|
+
metaType,
|
|
1191
|
+
metaId,
|
|
1192
|
+
rule,
|
|
1193
|
+
policy = {}
|
|
1194
|
+
} ) {
|
|
1195
|
+
/**
|
|
1196
|
+
* @type {MutationCreateRule}
|
|
1197
|
+
*/
|
|
1198
|
+
const query = await this.createMoleculeMutation( {
|
|
1199
|
+
mutationClass: MutationCreateRule,
|
|
1200
|
+
molecule: await this.createMolecule( {
|
|
1201
|
+
secret: this.getSecret(),
|
|
1202
|
+
sourceWallet: await this.getSourceWallet()
|
|
1203
|
+
} )
|
|
1204
|
+
}
|
|
1205
|
+
);
|
|
1206
|
+
|
|
1207
|
+
query.fillMolecule( {
|
|
1208
|
+
metaType,
|
|
1209
|
+
metaId,
|
|
1210
|
+
rule,
|
|
1211
|
+
policy
|
|
1212
|
+
} );
|
|
1213
|
+
|
|
1214
|
+
return await this.executeQuery( query );
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1181
1217
|
/**
|
|
1182
1218
|
* Builds and executes a molecule to convey new metadata to the ledger
|
|
1183
1219
|
*
|
|
@@ -1759,6 +1795,66 @@ export default class KnishIOClient {
|
|
|
1759
1795
|
}
|
|
1760
1796
|
|
|
1761
1797
|
|
|
1798
|
+
|
|
1799
|
+
/**
|
|
1800
|
+
* Builds and executes a molecule to destroy the specified Token units
|
|
1801
|
+
*
|
|
1802
|
+
* @param {string} token
|
|
1803
|
+
* @param {number|null} amount
|
|
1804
|
+
* @param {array|null} units
|
|
1805
|
+
* @param {Wallet|null} sourceWallet
|
|
1806
|
+
* @return {Promise<unknown>}
|
|
1807
|
+
*/
|
|
1808
|
+
async replenishToken ( {
|
|
1809
|
+
token,
|
|
1810
|
+
amount = null,
|
|
1811
|
+
units = [],
|
|
1812
|
+
sourceWallet = null
|
|
1813
|
+
} ) {
|
|
1814
|
+
|
|
1815
|
+
|
|
1816
|
+
if ( sourceWallet === null ) {
|
|
1817
|
+
sourceWallet = ( await this.queryBalance( { token } ) ).payload();
|
|
1818
|
+
}
|
|
1819
|
+
/*
|
|
1820
|
+
if ( !sourceWallet ) {
|
|
1821
|
+
throw new TransferWalletException( 'Source wallet is missing or invalid.' );
|
|
1822
|
+
}
|
|
1823
|
+
*/
|
|
1824
|
+
|
|
1825
|
+
// Remainder wallet
|
|
1826
|
+
let remainderWallet = Wallet.create( {
|
|
1827
|
+
secretOrBundle: this.getSecret(),
|
|
1828
|
+
token,
|
|
1829
|
+
characters: sourceWallet.characters
|
|
1830
|
+
} );
|
|
1831
|
+
|
|
1832
|
+
// Batch ID default initialization
|
|
1833
|
+
remainderWallet.initBatchId( {
|
|
1834
|
+
sourceWallet,
|
|
1835
|
+
isRemainder: true
|
|
1836
|
+
} );
|
|
1837
|
+
|
|
1838
|
+
|
|
1839
|
+
// Burn tokens
|
|
1840
|
+
let molecule = await this.createMolecule( {
|
|
1841
|
+
secret: null,
|
|
1842
|
+
sourceWallet,
|
|
1843
|
+
remainderWallet
|
|
1844
|
+
} );
|
|
1845
|
+
molecule.replenishToken( {
|
|
1846
|
+
amount,
|
|
1847
|
+
units
|
|
1848
|
+
} );
|
|
1849
|
+
molecule.sign( {} );
|
|
1850
|
+
molecule.check();
|
|
1851
|
+
|
|
1852
|
+
|
|
1853
|
+
const query = ( new MutationProposeMolecule( this.client(), molecule ) );
|
|
1854
|
+
return this.executeQuery( query );
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
|
|
1762
1858
|
/**
|
|
1763
1859
|
* Request a guest auth token
|
|
1764
1860
|
*
|
package/src/Molecule.js
CHANGED
|
@@ -56,10 +56,10 @@ import CheckMolecule from './libraries/check';
|
|
|
56
56
|
import { generateBundleHash } from './libraries/crypto';
|
|
57
57
|
import AtomsMissingException from './exception/AtomsMissingException';
|
|
58
58
|
import BalanceInsufficientException from './exception/BalanceInsufficientException';
|
|
59
|
-
import MetaMissingException from './exception/MetaMissingException';
|
|
60
59
|
import NegativeAmountException from './exception/NegativeAmountException';
|
|
61
60
|
import { deepCloning } from './libraries/array';
|
|
62
61
|
import Meta from './Meta';
|
|
62
|
+
import Rule from './instance/Rules/Rule';
|
|
63
63
|
|
|
64
64
|
const USE_META_CONTEXT = false;
|
|
65
65
|
const DEFAULT_META_CONTEXT = 'https://www.schema.org';
|
|
@@ -158,13 +158,26 @@ export default class Molecule {
|
|
|
158
158
|
meta = meta || {};
|
|
159
159
|
wallet = wallet || this.sourceWallet;
|
|
160
160
|
|
|
161
|
+
meta[ 'pubkey' ] = wallet.pubkey;
|
|
162
|
+
meta[ 'characters' ] = wallet.characters;
|
|
163
|
+
|
|
164
|
+
return meta;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
*
|
|
170
|
+
* @param wallet
|
|
171
|
+
* @param meta
|
|
172
|
+
* @returns {*[]}
|
|
173
|
+
*/
|
|
174
|
+
tokenUnitMetas ( wallet, meta = [] ) {
|
|
175
|
+
|
|
176
|
+
// Add token units meta key
|
|
161
177
|
if ( wallet.hasTokenUnits() ) {
|
|
162
178
|
meta[ 'tokenUnits' ] = wallet.tokenUnitsJson();
|
|
163
179
|
}
|
|
164
180
|
|
|
165
|
-
meta[ 'pubkey' ] = wallet.pubkey;
|
|
166
|
-
meta[ 'characters' ] = wallet.characters;
|
|
167
|
-
|
|
168
181
|
return meta;
|
|
169
182
|
}
|
|
170
183
|
|
|
@@ -187,49 +200,6 @@ export default class Molecule {
|
|
|
187
200
|
}
|
|
188
201
|
|
|
189
202
|
|
|
190
|
-
/*
|
|
191
|
-
* Replenishes non-finite token supplies
|
|
192
|
-
*
|
|
193
|
-
* @param {number} amount
|
|
194
|
-
* @param {string} token
|
|
195
|
-
* @param {array|object} metas
|
|
196
|
-
* @return {Molecule}
|
|
197
|
-
*/
|
|
198
|
-
replenishTokens ( {
|
|
199
|
-
amount,
|
|
200
|
-
token,
|
|
201
|
-
metas
|
|
202
|
-
} ) {
|
|
203
|
-
metas.action = 'add';
|
|
204
|
-
|
|
205
|
-
for ( let key of [ 'address', 'position', 'batchId' ] ) {
|
|
206
|
-
if ( typeof metas[ key ] === 'undefined' ) {
|
|
207
|
-
throw new MetaMissingException( `Molecule::replenishTokens() - Missing ${ key } in meta!` );
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
this.molecularHash = null;
|
|
212
|
-
|
|
213
|
-
this.atoms.push(
|
|
214
|
-
Atom.create.C( {
|
|
215
|
-
position: this.sourceWallet.position,
|
|
216
|
-
walletAddress: this.sourceWallet.address,
|
|
217
|
-
token: this.sourceWallet.token,
|
|
218
|
-
amount,
|
|
219
|
-
batchId: this.sourceWallet.batchId,
|
|
220
|
-
metaType: 'token',
|
|
221
|
-
metaId: token,
|
|
222
|
-
meta: this.finalMetas( metas ),
|
|
223
|
-
index: this.generateIndex()
|
|
224
|
-
} )
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
this.addUserRemainderAtom( this.remainderWallet );
|
|
228
|
-
this.atoms = Atom.sortAtoms( this.atoms );
|
|
229
|
-
|
|
230
|
-
return this;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
203
|
/**
|
|
234
204
|
* Add user remainder atom for ContinuID
|
|
235
205
|
*
|
|
@@ -291,6 +261,7 @@ export default class Molecule {
|
|
|
291
261
|
return this;
|
|
292
262
|
}
|
|
293
263
|
|
|
264
|
+
|
|
294
265
|
/**
|
|
295
266
|
* Burns some amount of tokens from a wallet
|
|
296
267
|
*
|
|
@@ -321,7 +292,7 @@ export default class Molecule {
|
|
|
321
292
|
token: this.sourceWallet.token,
|
|
322
293
|
value: -amount,
|
|
323
294
|
batchId: this.sourceWallet.batchId,
|
|
324
|
-
meta: this.finalMetas(
|
|
295
|
+
meta: this.finalMetas( this.tokenUnitMetas( this.sourceWallet ) ),
|
|
325
296
|
index: this.generateIndex()
|
|
326
297
|
} )
|
|
327
298
|
);
|
|
@@ -335,7 +306,7 @@ export default class Molecule {
|
|
|
335
306
|
batchId: this.remainderWallet.batchId,
|
|
336
307
|
metaType: walletBundle ? 'walletBundle' : null,
|
|
337
308
|
metaId: walletBundle,
|
|
338
|
-
meta: this.finalMetas(
|
|
309
|
+
meta: this.finalMetas( this.tokenUnitMetas( this.remainderWallet ), this.remainderWallet ),
|
|
339
310
|
index: this.generateIndex()
|
|
340
311
|
} )
|
|
341
312
|
);
|
|
@@ -346,6 +317,83 @@ export default class Molecule {
|
|
|
346
317
|
|
|
347
318
|
}
|
|
348
319
|
|
|
320
|
+
|
|
321
|
+
/*
|
|
322
|
+
* Replenishes non-finite token supplies
|
|
323
|
+
*
|
|
324
|
+
* @param {number} amount
|
|
325
|
+
* @param {string} token
|
|
326
|
+
* @param {array|object} metas
|
|
327
|
+
* @return {Molecule}
|
|
328
|
+
*/
|
|
329
|
+
replenishToken ( {
|
|
330
|
+
amount,
|
|
331
|
+
units = []
|
|
332
|
+
} ) {
|
|
333
|
+
|
|
334
|
+
if ( amount < 0 ) {
|
|
335
|
+
throw new NegativeAmountException( 'Molecule::replenishToken() - Amount to replenish must be positive!' );
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Special code for the token unit logic
|
|
339
|
+
if ( units.length ) {
|
|
340
|
+
|
|
341
|
+
// Prepare token units to formatted style
|
|
342
|
+
units = Wallet.getTokenUnits( units );
|
|
343
|
+
|
|
344
|
+
// Merge token units with source wallet & new items
|
|
345
|
+
this.remainderWallet.tokenUnits = this.sourceWallet.tokenUnits;
|
|
346
|
+
for ( const unit of units ) {
|
|
347
|
+
this.remainderWallet.tokenUnits.push( unit );
|
|
348
|
+
}
|
|
349
|
+
this.remainderWallet.balance = this.remainderWallet.tokenUnits.length;
|
|
350
|
+
|
|
351
|
+
// Override first atom'a token units to replenish values
|
|
352
|
+
this.sourceWallet.tokenUnits = units;
|
|
353
|
+
this.sourceWallet.balance = this.sourceWallet.tokenUnits.length;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Update wallet's balances
|
|
357
|
+
else {
|
|
358
|
+
this.remainderWallet.balance = this.sourceWallet.balance + amount;
|
|
359
|
+
this.sourceWallet.balance = amount;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
this.molecularHash = null;
|
|
363
|
+
|
|
364
|
+
// Initializing a new Atom to remove tokens from source
|
|
365
|
+
this.atoms.push(
|
|
366
|
+
Atom.create.V( {
|
|
367
|
+
position: this.sourceWallet.position,
|
|
368
|
+
walletAddress: this.sourceWallet.address,
|
|
369
|
+
token: this.sourceWallet.token,
|
|
370
|
+
value: this.sourceWallet.balance,
|
|
371
|
+
batchId: this.sourceWallet.batchId,
|
|
372
|
+
meta: this.finalMetas( this.tokenUnitMetas( this.sourceWallet ) ),
|
|
373
|
+
index: this.generateIndex()
|
|
374
|
+
} )
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
const walletBundle = this.remainderWallet.bundle;
|
|
378
|
+
this.atoms.push(
|
|
379
|
+
Atom.create.V( {
|
|
380
|
+
position: this.remainderWallet.position,
|
|
381
|
+
walletAddress: this.remainderWallet.address,
|
|
382
|
+
token: this.sourceWallet.token,
|
|
383
|
+
value: this.remainderWallet.balance,
|
|
384
|
+
batchId: this.remainderWallet.batchId,
|
|
385
|
+
metaType: walletBundle ? 'walletBundle' : null,
|
|
386
|
+
metaId: walletBundle,
|
|
387
|
+
meta: this.finalMetas( this.tokenUnitMetas( this.remainderWallet ), this.remainderWallet ),
|
|
388
|
+
index: this.generateIndex()
|
|
389
|
+
} )
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
this.atoms = Atom.sortAtoms( this.atoms );
|
|
393
|
+
|
|
394
|
+
return this;
|
|
395
|
+
}
|
|
396
|
+
|
|
349
397
|
/**
|
|
350
398
|
* Initialize a V-type molecule to transfer value from one wallet to another, with a third,
|
|
351
399
|
* regenerated wallet receiving the remainder
|
|
@@ -373,7 +421,7 @@ export default class Molecule {
|
|
|
373
421
|
token: this.sourceWallet.token,
|
|
374
422
|
value: -amount,
|
|
375
423
|
batchId: this.sourceWallet.batchId,
|
|
376
|
-
meta: this.finalMetas(
|
|
424
|
+
meta: this.finalMetas( this.tokenUnitMetas( this.sourceWallet ) ),
|
|
377
425
|
index: this.generateIndex()
|
|
378
426
|
} )
|
|
379
427
|
);
|
|
@@ -388,7 +436,7 @@ export default class Molecule {
|
|
|
388
436
|
batchId: recipientWallet.batchId,
|
|
389
437
|
metaType: 'walletBundle',
|
|
390
438
|
metaId: recipientWallet.bundle,
|
|
391
|
-
meta: this.finalMetas(
|
|
439
|
+
meta: this.finalMetas( this.tokenUnitMetas( recipientWallet ), recipientWallet ),
|
|
392
440
|
index: this.generateIndex()
|
|
393
441
|
} )
|
|
394
442
|
);
|
|
@@ -402,7 +450,7 @@ export default class Molecule {
|
|
|
402
450
|
batchId: this.remainderWallet.batchId,
|
|
403
451
|
metaType: 'walletBundle',
|
|
404
452
|
metaId: this.sourceWallet.bundle,
|
|
405
|
-
meta: this.finalMetas(
|
|
453
|
+
meta: this.finalMetas( this.tokenUnitMetas( this.remainderWallet ), this.remainderWallet ),
|
|
406
454
|
index: this.generateIndex()
|
|
407
455
|
} )
|
|
408
456
|
);
|
|
@@ -471,7 +519,7 @@ export default class Molecule {
|
|
|
471
519
|
for ( const walletKey of [ 'walletAddress', 'walletPosition', 'walletPubkey', 'walletCharacters' ] ) {
|
|
472
520
|
// Importing wallet fields into meta object
|
|
473
521
|
if ( !meta[ walletKey ] ) {
|
|
474
|
-
meta[ walletKey ] = recipientWallet[ walletKey.toLowerCase().
|
|
522
|
+
meta[ walletKey ] = recipientWallet[ walletKey.toLowerCase().substring( 6 ) ];
|
|
475
523
|
}
|
|
476
524
|
}
|
|
477
525
|
|
|
@@ -501,27 +549,28 @@ export default class Molecule {
|
|
|
501
549
|
*
|
|
502
550
|
* @param {string} metaType
|
|
503
551
|
* @param {string} metaId
|
|
504
|
-
* @param {object
|
|
552
|
+
* @param {object[]} rule,
|
|
553
|
+
* @param {object} policy
|
|
505
554
|
* @return {Molecule}
|
|
506
555
|
*/
|
|
507
556
|
createRule ( {
|
|
508
557
|
metaType,
|
|
509
558
|
metaId,
|
|
510
|
-
|
|
559
|
+
rule,
|
|
560
|
+
policy = {}
|
|
511
561
|
} ) {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
if ( typeof meta[ key ] === 'undefined' ) {
|
|
515
|
-
throw new MetaMissingException( `Molecule::createRule() - Value for required meta key ${ key } in missing!` );
|
|
516
|
-
}
|
|
562
|
+
const $rules = [];
|
|
517
563
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
meta[ key ] = JSON.stringify( meta[ key ] );
|
|
521
|
-
}
|
|
522
|
-
}
|
|
564
|
+
for ( const $rule of rule ) {
|
|
565
|
+
$rules.push( $rule instanceof Rule ? $rule : Rule.toObject( $rule ) );
|
|
523
566
|
}
|
|
524
567
|
|
|
568
|
+
const rules = {
|
|
569
|
+
rule: JSON.stringify( $rules )
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
const policies = Meta.policy( rules, policy );
|
|
573
|
+
|
|
525
574
|
this.addAtom(
|
|
526
575
|
Atom.create.R( {
|
|
527
576
|
position: this.sourceWallet.position,
|
|
@@ -529,7 +578,7 @@ export default class Molecule {
|
|
|
529
578
|
token: this.sourceWallet.token,
|
|
530
579
|
metaType,
|
|
531
580
|
metaId,
|
|
532
|
-
meta:
|
|
581
|
+
meta: { ...rules, ...policies },
|
|
533
582
|
index: this.generateIndex()
|
|
534
583
|
} )
|
|
535
584
|
);
|
|
@@ -45,7 +45,6 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
45
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
|
-
import { Operation } from '@apollo/client/core';
|
|
49
48
|
import { operationName } from '../libraries/ApolloLink/handler';
|
|
50
49
|
import Client from '../libraries/ApolloLink/Client';
|
|
51
50
|
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/*
|
|
2
|
+
(
|
|
3
|
+
(/(
|
|
4
|
+
(//(
|
|
5
|
+
(///(
|
|
6
|
+
(/////(
|
|
7
|
+
(//////( )
|
|
8
|
+
(////////( (/)
|
|
9
|
+
(////////( (///)
|
|
10
|
+
(//////////( (////)
|
|
11
|
+
(//////////( (//////)
|
|
12
|
+
(////////////( (///////)
|
|
13
|
+
(/////////////( (/////////)
|
|
14
|
+
(//////////////( (///////////)
|
|
15
|
+
(///////////////( (/////////////)
|
|
16
|
+
(////////////////( (//////////////)
|
|
17
|
+
((((((((((((((((((( (((((((((((((((
|
|
18
|
+
((((((((((((((((((( ((((((((((((((
|
|
19
|
+
((((((((((((((((((( ((((((((((((((
|
|
20
|
+
(((((((((((((((((((( (((((((((((((
|
|
21
|
+
(((((((((((((((((((( ((((((((((((
|
|
22
|
+
((((((((((((((((((( ((((((((((((
|
|
23
|
+
((((((((((((((((((( ((((((((((
|
|
24
|
+
((((((((((((((((((/ (((((((((
|
|
25
|
+
(((((((((((((((((( ((((((((
|
|
26
|
+
((((((((((((((((( (((((((
|
|
27
|
+
(((((((((((((((((( (((((
|
|
28
|
+
################# ##
|
|
29
|
+
################ #
|
|
30
|
+
################# ##
|
|
31
|
+
%################ ###
|
|
32
|
+
###############( ####
|
|
33
|
+
############### ####
|
|
34
|
+
############### ######
|
|
35
|
+
%#############( (#######
|
|
36
|
+
%############# #########
|
|
37
|
+
############( ##########
|
|
38
|
+
########### #############
|
|
39
|
+
######### ##############
|
|
40
|
+
%######
|
|
41
|
+
|
|
42
|
+
Powered by Knish.IO: Connecting a Decentralized World
|
|
43
|
+
|
|
44
|
+
Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
45
|
+
|
|
46
|
+
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
import Meta from './Meta';
|
|
50
|
+
import RuleArgumentException from './exception/RuleArgumentException';
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
export default class Callback {
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @param {string} action
|
|
58
|
+
* @param {Meta|null} meta
|
|
59
|
+
*/
|
|
60
|
+
constructor ( {
|
|
61
|
+
action,
|
|
62
|
+
meta
|
|
63
|
+
} ) {
|
|
64
|
+
if ( meta ) {
|
|
65
|
+
this.meta = meta;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if ( !action ) {
|
|
69
|
+
throw new RuleArgumentException( 'Callback structure violated, missing mandatory "action" parameter.' );
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this._action = action;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
set meta ( meta ) {
|
|
76
|
+
if ( ! ( meta instanceof Meta ) ) {
|
|
77
|
+
throw new RuleArgumentException( 'Incorrect meta argument. The meta argument can only be an instance of the Meta class.' );
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this._meta = meta;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
toJSON () {
|
|
84
|
+
const meta = {
|
|
85
|
+
action: this._action
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
if ( this._meta ) {
|
|
89
|
+
meta.meta = this._meta;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return meta;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* @param {object} object
|
|
98
|
+
*
|
|
99
|
+
* @return Callback
|
|
100
|
+
*/
|
|
101
|
+
static toObject ( object ) {
|
|
102
|
+
const callback = new Callback( {
|
|
103
|
+
action: object.action,
|
|
104
|
+
meta: null
|
|
105
|
+
} );
|
|
106
|
+
|
|
107
|
+
if ( object.meta ) {
|
|
108
|
+
callback.meta = new Meta( {
|
|
109
|
+
metaType: object.meta.metaType,
|
|
110
|
+
metaId: object.meta.metaId,
|
|
111
|
+
isotope: object.meta.isotope,
|
|
112
|
+
token: object.meta.token,
|
|
113
|
+
amount: object.meta.amount
|
|
114
|
+
} );
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return callback;
|
|
118
|
+
}
|
|
119
|
+
}
|