@cityofzion/bs-neo-legacy 1.10.8 → 1.10.10

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.
@@ -24,4 +24,6 @@ export declare class BSNeoLegacyConstants {
24
24
  static readonly MIGRATION_MIN_GAS = 0.1;
25
25
  static readonly MIGRATION_MIN_NEO = 2;
26
26
  static readonly MIGRATION_COZ_NEO3_ADDRESS = "NLMsicDapULKFDmAzTsbhwrZjYZ83j53Ty";
27
+ static MAX_TRANSACTION_SIZE_WITHOUT_FEE: number;
28
+ static FEE_APPLIED_TO_PLAYABLE_TRANSACTION: number;
27
29
  }
@@ -64,3 +64,5 @@ BSNeoLegacyConstants.MIGRATION_NEP_17_TRANSFER_FEE = 0.0112143;
64
64
  BSNeoLegacyConstants.MIGRATION_MIN_GAS = 0.1;
65
65
  BSNeoLegacyConstants.MIGRATION_MIN_NEO = 2;
66
66
  BSNeoLegacyConstants.MIGRATION_COZ_NEO3_ADDRESS = 'NLMsicDapULKFDmAzTsbhwrZjYZ83j53Ty';
67
+ BSNeoLegacyConstants.MAX_TRANSACTION_SIZE_WITHOUT_FEE = 1024;
68
+ BSNeoLegacyConstants.FEE_APPLIED_TO_PLAYABLE_TRANSACTION = 0.001;
@@ -36,7 +36,7 @@ class BSNeoLegacyHelper {
36
36
  return BSNeoLegacyConstants_1.BSNeoLegacyConstants.MAINNET_NETWORK_IDS.includes(network.id);
37
37
  }
38
38
  static normalizeHash(hash) {
39
- return hash.startsWith('0x') ? hash.slice(2) : hash;
39
+ return (0, blockchain_service_1.normalizeHash)(hash, { lowercase: false });
40
40
  }
41
41
  static waitForMigration(params) {
42
42
  return __awaiter(this, void 0, void 0, function* () {
@@ -63,7 +63,7 @@ export declare class BSNeoLegacy<BSName extends string = string> implements Bloc
63
63
  decrypt(encryptedKey: string, password: string): Promise<Account<BSName>>;
64
64
  encrypt(key: string, password: string): Promise<string>;
65
65
  transfer({ intents, senderAccount, tipIntent, ...params }: TransferParam<BSName>): Promise<string[]>;
66
- claim(account: Account): Promise<string>;
66
+ claim(account: Account<BSName>): Promise<string>;
67
67
  migrate({ account, neo3Address, neoLegacyMigrationAmounts }: MigrateParams<BSName>): Promise<string>;
68
68
  /**
69
69
  * Reference: https://github.com/CityOfZion/legacy-n3-swap-service/blob/master/policy/policy.go
@@ -24,7 +24,7 @@ var __rest = (this && this.__rest) || function (s, e) {
24
24
  }
25
25
  return t;
26
26
  };
27
- var _BSNeoLegacy_instances, _BSNeoLegacy_generateSigningCallback, _BSNeoLegacy_setTokens;
27
+ var _BSNeoLegacy_instances, _BSNeoLegacy_generateSigningCallback, _BSNeoLegacy_setTokens, _BSNeoLegacy_hasTransactionMoreThanMaxSize, _BSNeoLegacy_signTransfer, _BSNeoLegacy_sendTransfer, _BSNeoLegacy_signClaim, _BSNeoLegacy_sendClaim;
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.BSNeoLegacy = void 0;
30
30
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
@@ -134,54 +134,27 @@ class BSNeoLegacy {
134
134
  .toString()),
135
135
  ]);
136
136
  }
137
- let response;
138
- if (nep5ScriptBuilder.isEmpty()) {
139
- response = yield neon_js_1.api.sendAsset({
140
- account: neonJsAccount,
141
- api: apiProvider,
142
- url: this.network.url,
143
- intents: nativeIntents,
144
- fees: priorityFee,
145
- signingFunction: signingCallback,
146
- });
147
- }
148
- else {
149
- response = yield neon_js_1.api.doInvoke({
150
- intents: nativeIntents.length > 0 ? nativeIntents : undefined,
151
- account: neonJsAccount,
152
- api: apiProvider,
153
- script: nep5ScriptBuilder.str,
154
- url: this.network.url,
155
- fees: priorityFee,
156
- signingFunction: signingCallback,
157
- });
158
- }
159
- if (!response.tx)
160
- throw new Error('Failed to send transaction');
161
- return intents.map(() => response.tx.hash);
137
+ const hash = yield __classPrivateFieldGet(this, _BSNeoLegacy_instances, "m", _BSNeoLegacy_sendTransfer).call(this, {
138
+ account: neonJsAccount,
139
+ api: apiProvider,
140
+ url: this.network.url,
141
+ intents: nativeIntents.length > 0 ? nativeIntents : undefined,
142
+ signingFunction: signingCallback,
143
+ fees: priorityFee,
144
+ }, nep5ScriptBuilder);
145
+ return intents.map(() => hash);
162
146
  });
163
147
  }
164
148
  claim(account) {
165
149
  return __awaiter(this, void 0, void 0, function* () {
166
- const neoAccount = new neon_js_1.wallet.Account(account.key);
167
- const balances = yield this.blockchainDataService.getBalance(account.address);
168
- const neoBalance = balances.find(balance => balance.token.symbol === 'NEO');
169
- if (!neoBalance)
170
- throw new Error('It is necessary to have NEO to claim');
171
- const unclaimed = yield this.blockchainDataService.getUnclaimed(account.address);
172
- if (Number(unclaimed) <= 0)
173
- throw new Error(`Doesn't have gas to claim`);
150
+ const { neonJsAccount, signingCallback } = yield __classPrivateFieldGet(this, _BSNeoLegacy_instances, "m", _BSNeoLegacy_generateSigningCallback).call(this, account);
174
151
  const apiProvider = new neon_js_1.api.neoCli.instance(this.legacyNetwork);
175
- const claims = yield apiProvider.getClaims(account.address);
176
- const response = yield neon_js_1.api.claimGas({
177
- claims,
152
+ return yield __classPrivateFieldGet(this, _BSNeoLegacy_instances, "m", _BSNeoLegacy_sendClaim).call(this, {
178
153
  api: apiProvider,
179
- account: neoAccount,
154
+ account: neonJsAccount,
180
155
  url: this.network.url,
156
+ signingFunction: signingCallback,
181
157
  });
182
- if (!response.tx)
183
- throw new Error('Failed to claim');
184
- return response.tx.hash;
185
158
  });
186
159
  }
187
160
  migrate({ account, neo3Address, neoLegacyMigrationAmounts }) {
@@ -199,12 +172,11 @@ class BSNeoLegacy {
199
172
  intents.push(...neon_js_1.api.makeIntent({ [this.GAS_ASSET.symbol]: Number(neoLegacyMigrationAmounts.gasBalance.amount) }, BSNeoLegacyConstants_1.BSNeoLegacyConstants.MIGRATION_COZ_LEGACY_ADDRESS));
200
173
  if (neoLegacyMigrationAmounts.neoBalance)
201
174
  intents.push(...neon_js_1.api.makeIntent({ [this.NEO_ASSET.symbol]: Number(neoLegacyMigrationAmounts.neoBalance.amount) }, BSNeoLegacyConstants_1.BSNeoLegacyConstants.MIGRATION_COZ_LEGACY_ADDRESS));
202
- const response = yield neon_js_1.api.sendAsset({
175
+ return yield __classPrivateFieldGet(this, _BSNeoLegacy_instances, "m", _BSNeoLegacy_sendTransfer).call(this, {
203
176
  url: this.network.url,
204
177
  api: provider,
205
178
  account: neonJsAccount,
206
179
  intents,
207
- fees: 0,
208
180
  signingFunction: signingCallback,
209
181
  override: {
210
182
  attributes: [
@@ -219,9 +191,6 @@ class BSNeoLegacy {
219
191
  ],
220
192
  },
221
193
  });
222
- if (!response.tx)
223
- throw new Error('Migration failed on send');
224
- return response.tx.hash;
225
194
  });
226
195
  }
227
196
  /**
@@ -292,6 +261,7 @@ _BSNeoLegacy_instances = new WeakSet(), _BSNeoLegacy_generateSigningCallback = f
292
261
  }
293
262
  return {
294
263
  neonJsAccount,
264
+ signingCallback: neon_js_1.api.signWithPrivateKey(neonJsAccount.privateKey),
295
265
  };
296
266
  });
297
267
  }, _BSNeoLegacy_setTokens = function _BSNeoLegacy_setTokens(network) {
@@ -301,4 +271,56 @@ _BSNeoLegacy_instances = new WeakSet(), _BSNeoLegacy_generateSigningCallback = f
301
271
  this.feeToken = tokens.find(token => token.symbol === 'GAS');
302
272
  this.burnToken = tokens.find(token => token.symbol === 'NEO');
303
273
  this.claimToken = tokens.find(token => token.symbol === 'GAS');
274
+ }, _BSNeoLegacy_hasTransactionMoreThanMaxSize = function _BSNeoLegacy_hasTransactionMoreThanMaxSize(config) {
275
+ if (!config.fees || config.fees < BSNeoLegacyConstants_1.BSNeoLegacyConstants.FEE_APPLIED_TO_PLAYABLE_TRANSACTION) {
276
+ const serializedTransaction = config.tx.serialize(true);
277
+ const transactionSize = serializedTransaction.length / 2;
278
+ if (transactionSize > BSNeoLegacyConstants_1.BSNeoLegacyConstants.MAX_TRANSACTION_SIZE_WITHOUT_FEE) {
279
+ return true;
280
+ }
281
+ }
282
+ return false;
283
+ }, _BSNeoLegacy_signTransfer = function _BSNeoLegacy_signTransfer(config, nep5ScriptBuilder) {
284
+ return __awaiter(this, void 0, void 0, function* () {
285
+ if (!nep5ScriptBuilder || nep5ScriptBuilder.isEmpty()) {
286
+ config = yield neon_js_1.api.createContractTx(config);
287
+ }
288
+ else {
289
+ config.script = nep5ScriptBuilder.str;
290
+ config = yield neon_js_1.api.createInvocationTx(config);
291
+ }
292
+ config = yield neon_js_1.api.modifyTransactionForEmptyTransaction(config);
293
+ config = yield neon_js_1.api.addAttributeIfExecutingAsSmartContract(config);
294
+ config = yield neon_js_1.api.signTx(config);
295
+ config = yield neon_js_1.api.addSignatureIfExecutingAsSmartContract(config);
296
+ return config;
297
+ });
298
+ }, _BSNeoLegacy_sendTransfer = function _BSNeoLegacy_sendTransfer(config, nep5ScriptBuilder) {
299
+ return __awaiter(this, void 0, void 0, function* () {
300
+ const sharedConfig = yield neon_js_1.api.fillBalance(config);
301
+ let signedConfig = yield __classPrivateFieldGet(this, _BSNeoLegacy_instances, "m", _BSNeoLegacy_signTransfer).call(this, Object.assign({}, sharedConfig), nep5ScriptBuilder);
302
+ if (__classPrivateFieldGet(this, _BSNeoLegacy_instances, "m", _BSNeoLegacy_hasTransactionMoreThanMaxSize).call(this, signedConfig)) {
303
+ signedConfig = yield __classPrivateFieldGet(this, _BSNeoLegacy_instances, "m", _BSNeoLegacy_signTransfer).call(this, Object.assign(Object.assign({}, sharedConfig), { fees: BSNeoLegacyConstants_1.BSNeoLegacyConstants.FEE_APPLIED_TO_PLAYABLE_TRANSACTION }), nep5ScriptBuilder);
304
+ }
305
+ signedConfig = yield neon_js_1.api.sendTx(signedConfig);
306
+ return signedConfig.response.txid;
307
+ });
308
+ }, _BSNeoLegacy_signClaim = function _BSNeoLegacy_signClaim(config) {
309
+ return __awaiter(this, void 0, void 0, function* () {
310
+ config = yield neon_js_1.api.createClaimTx(config);
311
+ config = yield neon_js_1.api.addAttributeIfExecutingAsSmartContract(config);
312
+ config = yield neon_js_1.api.signTx(config);
313
+ config = yield neon_js_1.api.addSignatureIfExecutingAsSmartContract(config);
314
+ return config;
315
+ });
316
+ }, _BSNeoLegacy_sendClaim = function _BSNeoLegacy_sendClaim(config) {
317
+ return __awaiter(this, void 0, void 0, function* () {
318
+ const sharedConfig = yield neon_js_1.api.fillClaims(config);
319
+ let signedConfig = yield __classPrivateFieldGet(this, _BSNeoLegacy_instances, "m", _BSNeoLegacy_signClaim).call(this, Object.assign({}, sharedConfig));
320
+ if (__classPrivateFieldGet(this, _BSNeoLegacy_instances, "m", _BSNeoLegacy_hasTransactionMoreThanMaxSize).call(this, signedConfig)) {
321
+ signedConfig = yield __classPrivateFieldGet(this, _BSNeoLegacy_instances, "m", _BSNeoLegacy_signClaim).call(this, Object.assign(Object.assign({}, sharedConfig), { fees: BSNeoLegacyConstants_1.BSNeoLegacyConstants.FEE_APPLIED_TO_PLAYABLE_TRANSACTION }));
322
+ }
323
+ signedConfig = yield neon_js_1.api.sendTx(signedConfig);
324
+ return signedConfig.response.txid;
325
+ });
304
326
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-neo-legacy",
3
- "version": "1.10.8",
3
+ "version": "1.10.10",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "Coz",
@@ -12,7 +12,7 @@
12
12
  "@cityofzion/dora-ts": "0.0.11",
13
13
  "@cityofzion/neon-js": "4.8.3",
14
14
  "@ledgerhq/hw-transport": "~6.30.5",
15
- "@cityofzion/blockchain-service": "1.16.3",
15
+ "@cityofzion/blockchain-service": "1.17.0",
16
16
  "@cityofzion/bs-asteroid-sdk": "0.9.1"
17
17
  },
18
18
  "devDependencies": {