@wishknish/knishio-client-ts 0.7.6 → 0.7.7

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/index.js CHANGED
@@ -4803,6 +4803,7 @@ var Molecule = class _Molecule {
4803
4803
  remainderWallet;
4804
4804
  atoms;
4805
4805
  version;
4806
+ continuIdPosition;
4806
4807
  parentHashes;
4807
4808
  local;
4808
4809
  /**
@@ -4815,7 +4816,8 @@ var Molecule = class _Molecule {
4815
4816
  sourceWallet = null,
4816
4817
  remainderWallet = null,
4817
4818
  cellSlug = null,
4818
- version = null
4819
+ version = null,
4820
+ continuIdPosition = null
4819
4821
  } = {}) {
4820
4822
  this.status = null;
4821
4823
  this.molecularHash = null;
@@ -4824,6 +4826,7 @@ var Molecule = class _Molecule {
4824
4826
  this.secret = secret;
4825
4827
  this.bundle = bundle;
4826
4828
  this.sourceWallet = sourceWallet;
4829
+ this.continuIdPosition = continuIdPosition;
4827
4830
  this.atoms = [];
4828
4831
  this.parentHashes = [];
4829
4832
  const versionRegistry = versions_default;
@@ -4901,7 +4904,9 @@ var Molecule = class _Molecule {
4901
4904
  });
4902
4905
  }
4903
4906
  const continuIdMeta = {};
4904
- if (this.sourceWallet && this.sourceWallet.position) {
4907
+ if (this.continuIdPosition) {
4908
+ continuIdMeta.previousPosition = this.continuIdPosition;
4909
+ } else if (this.sourceWallet && this.sourceWallet.position) {
4905
4910
  continuIdMeta.previousPosition = this.sourceWallet.position;
4906
4911
  }
4907
4912
  if (this.remainderWallet.pubkey) {
@@ -5245,10 +5250,21 @@ var Molecule = class _Molecule {
5245
5250
  if (Number(this.sourceWallet.balance) - amount < 0) {
5246
5251
  throw new BalanceInsufficientException();
5247
5252
  }
5253
+ const burnWallet = new Wallet({
5254
+ bundle: "0000000000000000000000000000000000000000000000000000000000000000",
5255
+ token: this.sourceWallet.token
5256
+ });
5248
5257
  this.addAtom(Atom.create({
5249
5258
  isotope: "V",
5250
5259
  wallet: this.sourceWallet,
5251
- value: -amount
5260
+ value: -Number(this.sourceWallet.balance)
5261
+ }));
5262
+ this.addAtom(Atom.create({
5263
+ isotope: "V",
5264
+ wallet: burnWallet,
5265
+ value: amount,
5266
+ metaType: "walletBundle",
5267
+ metaId: burnWallet.bundle
5252
5268
  }));
5253
5269
  this.addAtom(Atom.create({
5254
5270
  isotope: "V",
@@ -10138,6 +10154,17 @@ var KnishIOClient = class {
10138
10154
  this.log("info", "KnishIOClient::createMolecule() - Creating a new molecule...");
10139
10155
  secret = secret || this.getSecret();
10140
10156
  bundle = bundle || this.getBundle();
10157
+ let continuIdPosition = null;
10158
+ if (sourceWallet && sourceWallet.token !== "USER") {
10159
+ if (this.lastMoleculeQuery && this.getRemainderWallet() && this.getRemainderWallet()?.token === "USER" && this.lastMoleculeQuery.response() && this.lastMoleculeQuery.response()?.success()) {
10160
+ continuIdPosition = this.getRemainderWallet()?.position || null;
10161
+ this.log("info", `KnishIOClient::createMolecule() - Captured USER ContinuID position ${continuIdPosition?.substring(0, 16)}... for non-USER source wallet`);
10162
+ } else {
10163
+ const userWallet = await this.getSourceWallet();
10164
+ continuIdPosition = userWallet?.position || null;
10165
+ this.log("info", `KnishIOClient::createMolecule() - Queried USER ContinuID position ${continuIdPosition?.substring(0, 16)}... for non-USER source wallet`);
10166
+ }
10167
+ }
10141
10168
  if (!sourceWallet && this.lastMoleculeQuery && this.getRemainderWallet()?.token === "USER" && this.lastMoleculeQuery.response() && this.lastMoleculeQuery.response()?.success()) {
10142
10169
  sourceWallet = this.getRemainderWallet();
10143
10170
  this.log("info", `KnishIOClient::createMolecule() - Using carry-forward remainder wallet at position ${sourceWallet?.position?.substring(0, 16)}...`);
@@ -10157,7 +10184,8 @@ var KnishIOClient = class {
10157
10184
  sourceWallet,
10158
10185
  remainderWallet: this.getRemainderWallet(),
10159
10186
  cellSlug: this.getCellSlug(),
10160
- version: this.getServerSdkVersion()
10187
+ version: this.getServerSdkVersion(),
10188
+ continuIdPosition
10161
10189
  });
10162
10190
  }
10163
10191
  /**
@@ -10888,8 +10916,10 @@ var KnishIOClient = class {
10888
10916
  amount: amount || 0
10889
10917
  });
10890
10918
  }
10919
+ const remainderWallet = sourceWallet.createRemainder(this.getSecret());
10891
10920
  const molecule = await this.createMolecule({
10892
- sourceWallet
10921
+ sourceWallet,
10922
+ remainderWallet
10893
10923
  });
10894
10924
  const mutation = await this.createMoleculeMutation({
10895
10925
  mutationClass: MutationTransferTokens,
@@ -11185,7 +11215,15 @@ var KnishIOClient = class {
11185
11215
  amount
11186
11216
  });
11187
11217
  }
11188
- const mutation = await this.createMoleculeMutation({ mutationClass: MutationDepositBufferToken });
11218
+ const remainderWallet = sourceWallet.createRemainder(this.getSecret());
11219
+ const molecule = await this.createMolecule({
11220
+ sourceWallet,
11221
+ remainderWallet
11222
+ });
11223
+ const mutation = await this.createMoleculeMutation({
11224
+ mutationClass: MutationDepositBufferToken,
11225
+ molecule
11226
+ });
11189
11227
  await mutation.fillMolecule({
11190
11228
  amount: typeof amount === "string" ? Number(amount) : amount,
11191
11229
  tradeRates