@exodus/solana-lib 1.2.9-build → 1.2.9

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 (60) hide show
  1. package/package.json +3 -3
  2. package/src/constants.js +12 -0
  3. package/src/encode.js +57 -0
  4. package/src/fee-data/index.js +1 -0
  5. package/src/fee-data/solana.js +9 -0
  6. package/src/helpers/spl-token.js +108 -0
  7. package/src/helpers/tokenTransfer.js +72 -0
  8. package/src/index.js +8 -0
  9. package/src/keypair.js +32 -0
  10. package/src/tokens.js +19 -0
  11. package/src/transaction.js +240 -0
  12. package/src/tx/create-and-sign-tx.js +8 -0
  13. package/{lib → src}/tx/create-unsigned-tx.js +11 -18
  14. package/src/tx/index.js +4 -0
  15. package/src/tx/parse-unsigned-tx.js +41 -0
  16. package/src/tx/sign-unsigned-tx.js +78 -0
  17. package/src/vendor/account.js +38 -0
  18. package/src/vendor/index.js +9 -0
  19. package/src/vendor/instruction.js +46 -0
  20. package/src/vendor/message.js +216 -0
  21. package/src/vendor/nonce-account.js +46 -0
  22. package/src/vendor/publickey.js +212 -0
  23. package/src/vendor/stake-program.js +527 -0
  24. package/src/vendor/system-program.js +782 -0
  25. package/src/vendor/sysvar.js +16 -0
  26. package/src/vendor/transaction.js +594 -0
  27. package/src/vendor/utils/blockhash.js +6 -0
  28. package/src/vendor/utils/fee-calculator.js +17 -0
  29. package/src/vendor/utils/layout.js +80 -0
  30. package/src/vendor/utils/shortvec-encoding.js +30 -0
  31. package/src/vendor/utils/to-buffer.js +9 -0
  32. package/lib/constants.js +0 -19
  33. package/lib/encode.js +0 -67
  34. package/lib/fee-data/index.js +0 -15
  35. package/lib/fee-data/solana.js +0 -14
  36. package/lib/helpers/spl-token.js +0 -122
  37. package/lib/helpers/tokenTransfer.js +0 -78
  38. package/lib/index.js +0 -79
  39. package/lib/keypair.js +0 -38
  40. package/lib/tokens.js +0 -21
  41. package/lib/transaction.js +0 -279
  42. package/lib/tx/create-and-sign-tx.js +0 -15
  43. package/lib/tx/index.js +0 -53
  44. package/lib/tx/parse-unsigned-tx.js +0 -55
  45. package/lib/tx/sign-unsigned-tx.js +0 -90
  46. package/lib/vendor/account.js +0 -48
  47. package/lib/vendor/index.js +0 -113
  48. package/lib/vendor/instruction.js +0 -48
  49. package/lib/vendor/message.js +0 -167
  50. package/lib/vendor/nonce-account.js +0 -56
  51. package/lib/vendor/publickey.js +0 -211
  52. package/lib/vendor/stake-program.js +0 -476
  53. package/lib/vendor/system-program.js +0 -640
  54. package/lib/vendor/sysvar.js +0 -19
  55. package/lib/vendor/transaction.js +0 -594
  56. package/lib/vendor/utils/blockhash.js +0 -1
  57. package/lib/vendor/utils/fee-calculator.js +0 -25
  58. package/lib/vendor/utils/layout.js +0 -97
  59. package/lib/vendor/utils/shortvec-encoding.js +0 -41
  60. package/lib/vendor/utils/to-buffer.js +0 -18
@@ -1,279 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _assert = _interopRequireDefault(require("assert"));
9
-
10
- var _keypair = require("./keypair");
11
-
12
- var _encode = require("./encode");
13
-
14
- var _tokenTransfer = require("./helpers/tokenTransfer");
15
-
16
- var _vendor = require("./vendor");
17
-
18
- var _constants = require("./constants");
19
-
20
- var _tokens = _interopRequireDefault(require("./tokens"));
21
-
22
- var _bs = _interopRequireDefault(require("bs58"));
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- class Tx {
27
- constructor({
28
- from,
29
- to,
30
- amount,
31
- recentBlockhash,
32
- // fee, // (Fee per Signature: 5000 lamports)
33
- // Tokens related:
34
- tokenName,
35
- destinationAddressType,
36
- isAssociatedTokenAccountActive,
37
- // true when recipient balance !== 0
38
- fromTokenAddresses // sender token addresses
39
-
40
- } = {}) {
41
- (0, _assert.default)(from, 'from is required');
42
- (0, _assert.default)(to, 'to is required');
43
- (0, _assert.default)(amount, 'amount is required');
44
- (0, _assert.default)(typeof amount === 'number', 'amount must be a number');
45
- (0, _assert.default)(recentBlockhash, 'recentBlockhash is required');
46
-
47
- if (tokenName) {
48
- (0, _assert.default)(typeof destinationAddressType !== 'undefined', 'destinationAddressType is required when sending tokens');
49
- (0, _assert.default)(typeof isAssociatedTokenAccountActive !== 'undefined', 'isAssociatedTokenAccountActive is required when sending tokens'); // needed to create the recipient account
50
-
51
- (0, _assert.default)(Array.isArray(fromTokenAddresses), 'fromTokenAddresses Array is required');
52
- }
53
-
54
- const token = _tokens.default.find(({
55
- tokenName: name
56
- }) => name === tokenName);
57
-
58
- this.txObj = {
59
- from,
60
- to,
61
- amount,
62
- recentBlockhash,
63
- token,
64
- destinationAddressType,
65
- isAssociatedTokenAccountActive,
66
- fromTokenAddresses
67
- };
68
-
69
- if (token) {
70
- // TOKEN transfer tx
71
- this.buildTokenTransaction(this.txObj);
72
- } else {
73
- // SOL tx
74
- this.buildSOLtransaction(this.txObj);
75
- }
76
- }
77
-
78
- buildSOLtransaction({
79
- from,
80
- to,
81
- amount,
82
- recentBlockhash
83
- }) {
84
- const txInstruction = _vendor.SystemProgram.transfer({
85
- fromPubkey: new _vendor.PublicKey(from),
86
- toPubkey: new _vendor.PublicKey(to),
87
- lamports: amount
88
- });
89
-
90
- this.transaction = new _vendor.Transaction({
91
- instructions: [txInstruction],
92
- recentBlockhash
93
- });
94
- }
95
-
96
- buildTokenTransaction({
97
- from,
98
- to,
99
- amount,
100
- recentBlockhash,
101
- token,
102
- destinationAddressType,
103
- isAssociatedTokenAccountActive,
104
- fromTokenAddresses
105
- }) {
106
- this.transaction = new _vendor.Transaction({
107
- recentBlockhash
108
- });
109
- const isUnknown = destinationAddressType === null;
110
- const isSOLaddress = destinationAddressType === 'solana'; // crete account instruction
111
-
112
- if (isUnknown) throw new Error('Destination SOL balance cannot be zero (address not active)'); // cannot initialize without knowing the owner
113
-
114
- if (isSOLaddress && !isAssociatedTokenAccountActive) this.transaction.add((0, _tokenTransfer.createAssociatedTokenAccount)(from, token.mintAddress, to));
115
- let amountLeft = amount;
116
- let amountToSend;
117
-
118
- for (let {
119
- ticker,
120
- tokenAccountAddress,
121
- balance
122
- } of fromTokenAddresses) {
123
- // need to add more of this instruction until we reach the desired balance (amount) to send
124
- (0, _assert.default)(ticker === token.tokenSymbol, `Got unexpected ticker ${ticker}`);
125
- if (amountLeft === 0) break;
126
- balance = Number(balance);
127
-
128
- if (balance >= amountLeft) {
129
- amountToSend = amountLeft;
130
- amountLeft = 0;
131
- } else {
132
- amountToSend = balance; // not enough balance
133
-
134
- amountLeft -= amountToSend;
135
- }
136
-
137
- const dest = isSOLaddress ? (0, _encode.findAssociatedTokenAddress)(to, token.mintAddress) : to; // add transfer token instruction
138
-
139
- this.transaction.add((0, _tokenTransfer.createTokenTransferInstruction)(from, tokenAccountAddress, dest, amountToSend));
140
- }
141
-
142
- (0, _assert.default)(amountLeft === 0, `Not enough balance to send ${amount} ${token.tokenSymbol}`);
143
- }
144
-
145
- static createStakeAccountTransaction({
146
- address,
147
- amount,
148
- seed = _constants.SEED,
149
- pool,
150
- recentBlockhash
151
- }) {
152
- const fromPubkey = new _vendor.PublicKey(address);
153
- const stakeAddress = (0, _encode.createStakeAddress)(address, seed);
154
- const stakePublicKey = new _vendor.PublicKey(stakeAddress);
155
- const poolKey = new _vendor.PublicKey(pool);
156
- const authorized = new _vendor.Authorized(fromPubkey, fromPubkey); // staker, withdrawer
157
-
158
- const lockup = new _vendor.Lockup(0, 0, fromPubkey); // no lockup
159
- // create account instruction
160
-
161
- const programTx = _vendor.StakeProgram.createAccountWithSeed({
162
- fromPubkey,
163
- stakePubkey: stakePublicKey,
164
- basePubkey: fromPubkey,
165
- seed,
166
- authorized,
167
- lockup,
168
- lamports: amount // number
169
-
170
- }); // delegate funds instruction
171
-
172
-
173
- const delegateTx = _vendor.StakeProgram.delegate({
174
- stakePubkey: stakePublicKey,
175
- authorizedPubkey: fromPubkey,
176
- votePubkey: poolKey // pool vote key
177
-
178
- });
179
-
180
- const transaction = new _vendor.Transaction({
181
- recentBlockhash
182
- }).add(programTx).add(delegateTx);
183
- return transaction;
184
- }
185
-
186
- static undelegate({
187
- address,
188
- stakeAddresses,
189
- recentBlockhash
190
- }) {
191
- // undelegate all stake addresses
192
- (0, _assert.default)(Array.isArray(stakeAddresses), 'stakeAddresses Array is required');
193
- const fromPubkey = new _vendor.PublicKey(address);
194
- const transaction = new _vendor.Transaction({
195
- recentBlockhash
196
- });
197
- stakeAddresses.forEach(stakeAddress => {
198
- const stakePublicKey = new _vendor.PublicKey(stakeAddress);
199
-
200
- const programTx = _vendor.StakeProgram.deactivate({
201
- stakePubkey: stakePublicKey,
202
- authorizedPubkey: fromPubkey
203
- });
204
-
205
- transaction.add(programTx);
206
- });
207
- return transaction;
208
- }
209
-
210
- static withdraw({
211
- address,
212
- stakeAddresses,
213
- amount,
214
- recentBlockhash
215
- }) {
216
- const fromPubkey = new _vendor.PublicKey(address);
217
- const stakeAddress = Array.isArray(stakeAddresses) ? stakeAddresses[0] : stakeAddresses;
218
- const stakePublicKey = new _vendor.PublicKey(stakeAddress);
219
-
220
- const transaction = _vendor.StakeProgram.withdraw({
221
- stakePubkey: stakePublicKey,
222
- authorizedPubkey: fromPubkey,
223
- toPubkey: fromPubkey,
224
- lamports: amount
225
- });
226
-
227
- transaction.recentBlockhash = recentBlockhash;
228
- return transaction;
229
- }
230
-
231
- static sign(tx, privateKey) {
232
- if (!privateKey) throw new Error('Please provide a secretKey');
233
- const {
234
- secretKey
235
- } = (0, _keypair.getKeyPairFromPrivateKey)(privateKey);
236
- const signers = [new _vendor.Account(secretKey)];
237
- let transaction = tx;
238
- if (tx instanceof Tx) transaction = tx.transaction;
239
- transaction.sign(...signers);
240
-
241
- if (!transaction.signature) {
242
- throw new Error('!signature'); // should never happen
243
- }
244
- }
245
-
246
- serialize() {
247
- const wireTransaction = this.transaction.serialize();
248
- return wireTransaction.toString('base64');
249
- }
250
-
251
- static serialize(tx) {
252
- let transaction = tx;
253
- if (tx instanceof Tx) transaction = tx.transaction;
254
- return transaction.serialize().toString('base64');
255
- }
256
-
257
- getTxId() {
258
- if (!this.transaction.signature) {
259
- throw new Error('Cannot get txId, tx is not signed');
260
- }
261
-
262
- return _bs.default.encode(this.transaction.signature);
263
- }
264
-
265
- static getTxId(tx) {
266
- let transaction = tx;
267
- if (tx instanceof Tx) transaction = tx.transaction;
268
-
269
- if (!transaction.signature) {
270
- throw new Error('Cannot get txId, tx is not signed');
271
- }
272
-
273
- return _bs.default.encode(transaction.signature);
274
- }
275
-
276
- }
277
-
278
- var _default = Tx;
279
- exports.default = _default;
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createAndSignTx = createAndSignTx;
7
-
8
- var _createUnsignedTx = require("./create-unsigned-tx");
9
-
10
- var _signUnsignedTx = require("./sign-unsigned-tx");
11
-
12
- function createAndSignTx(input, privateKey) {
13
- const unsignedTx = (0, _createUnsignedTx.createUnsignedTx)(input);
14
- return (0, _signUnsignedTx.signUnsignedTx)(unsignedTx, privateKey);
15
- }
package/lib/tx/index.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _signUnsignedTx = require("./sign-unsigned-tx");
8
-
9
- Object.keys(_signUnsignedTx).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- Object.defineProperty(exports, key, {
12
- enumerable: true,
13
- get: function () {
14
- return _signUnsignedTx[key];
15
- }
16
- });
17
- });
18
-
19
- var _parseUnsignedTx = require("./parse-unsigned-tx");
20
-
21
- Object.keys(_parseUnsignedTx).forEach(function (key) {
22
- if (key === "default" || key === "__esModule") return;
23
- Object.defineProperty(exports, key, {
24
- enumerable: true,
25
- get: function () {
26
- return _parseUnsignedTx[key];
27
- }
28
- });
29
- });
30
-
31
- var _createUnsignedTx = require("./create-unsigned-tx");
32
-
33
- Object.keys(_createUnsignedTx).forEach(function (key) {
34
- if (key === "default" || key === "__esModule") return;
35
- Object.defineProperty(exports, key, {
36
- enumerable: true,
37
- get: function () {
38
- return _createUnsignedTx[key];
39
- }
40
- });
41
- });
42
-
43
- var _createAndSignTx = require("./create-and-sign-tx");
44
-
45
- Object.keys(_createAndSignTx).forEach(function (key) {
46
- if (key === "default" || key === "__esModule") return;
47
- Object.defineProperty(exports, key, {
48
- enumerable: true,
49
- get: function () {
50
- return _createAndSignTx[key];
51
- }
52
- });
53
- });
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.parseUnsignedTx = parseUnsignedTx;
7
-
8
- var _assets = _interopRequireDefault(require("@exodus/assets"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
13
-
14
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
15
-
16
- function parseUnsignedTx(unsignedTx) {
17
- const asset = _assets.default.solana;
18
-
19
- const _unsignedTx$txData = unsignedTx.txData,
20
- {
21
- from,
22
- to,
23
- recentBlockhash,
24
- tokenName,
25
- destinationAddressType,
26
- isAssociatedTokenAccountActive,
27
- fromTokenAddresses,
28
- method,
29
- stakeAddresses,
30
- seed,
31
- pool
32
- } = _unsignedTx$txData,
33
- txData = _objectWithoutProperties(_unsignedTx$txData, ["from", "to", "recentBlockhash", "tokenName", "destinationAddressType", "isAssociatedTokenAccountActive", "fromTokenAddresses", "method", "stakeAddresses", "seed", "pool"]);
34
-
35
- const amount = asset.currency.baseUnit(txData.amount);
36
- const fee = asset.currency.baseUnit(txData.fee);
37
- return {
38
- asset,
39
- from: [from],
40
- to,
41
- amount,
42
- fee,
43
- recentBlockhash,
44
- // token related
45
- tokenName,
46
- destinationAddressType,
47
- isAssociatedTokenAccountActive,
48
- fromTokenAddresses,
49
- // staking related
50
- method,
51
- stakeAddresses,
52
- seed,
53
- pool
54
- };
55
- }
@@ -1,90 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.signUnsignedTx = signUnsignedTx;
7
-
8
- var _assets = _interopRequireDefault(require("@exodus/assets"));
9
-
10
- var _ = require("../");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- function signUnsignedTx(unsignedTx, privateKey) {
15
- const {
16
- from,
17
- to,
18
- amount: unitAmount,
19
- recentBlockhash,
20
- // tokens related
21
- tokenName,
22
- destinationAddressType,
23
- isAssociatedTokenAccountActive,
24
- fromTokenAddresses,
25
- // staking related
26
- stakeAddresses,
27
- method,
28
- seed,
29
- pool
30
- } = unsignedTx.txData;
31
- const asset = _assets.default.solana;
32
- const address = from;
33
- const amount = unitAmount ? asset.currency.baseUnit(unitAmount).toNumber() : unitAmount;
34
- let tx;
35
-
36
- switch (method) {
37
- case 'delegate':
38
- tx = _.Transaction.createStakeAccountTransaction({
39
- address,
40
- amount,
41
- recentBlockhash,
42
- seed,
43
- pool
44
- });
45
- break;
46
-
47
- case 'undelegate':
48
- tx = _.Transaction.undelegate({
49
- address,
50
- stakeAddresses,
51
- recentBlockhash
52
- });
53
- break;
54
-
55
- case 'withdraw':
56
- tx = _.Transaction.withdraw({
57
- address,
58
- stakeAddresses,
59
- amount,
60
- recentBlockhash
61
- });
62
- break;
63
-
64
- default:
65
- // SOL and Token tx
66
- tx = new _.Transaction({
67
- from,
68
- to,
69
- amount,
70
- recentBlockhash,
71
- tokenName,
72
- destinationAddressType,
73
- isAssociatedTokenAccountActive,
74
- fromTokenAddresses
75
- });
76
- break;
77
- } // sign plain tx
78
-
79
-
80
- _.Transaction.sign(tx, privateKey);
81
-
82
- const rawTx = _.Transaction.serialize(tx);
83
-
84
- const txId = _.Transaction.getTxId(tx);
85
-
86
- return {
87
- txId,
88
- rawTx
89
- };
90
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Account = void 0;
7
-
8
- var _publickey = require("./publickey");
9
-
10
- var _keypair = require("../keypair");
11
-
12
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
-
14
- class Account {
15
- /**
16
- * Create a new Account object
17
- *
18
- * @param secretKey Secret key for the account
19
- */
20
- constructor(secretKey) {
21
- _defineProperty(this, "_keypair", void 0);
22
-
23
- if (secretKey) {
24
- this._keypair = (0, _keypair.getKeyPairFromPrivateKey)(Buffer.from(secretKey, 'hex'));
25
- } else {
26
- throw new Error('Please provide a secretKey');
27
- }
28
- }
29
- /**
30
- * The public key for this account
31
- */
32
-
33
-
34
- get publicKey() {
35
- return new _publickey.PublicKey(this._keypair.publicKey);
36
- }
37
- /**
38
- * The **unencrypted** secret key for this account
39
- */
40
-
41
-
42
- get secretKey() {
43
- return this._keypair.secretKey;
44
- }
45
-
46
- }
47
-
48
- exports.Account = Account;
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _account = require("./account");
8
-
9
- Object.keys(_account).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- Object.defineProperty(exports, key, {
12
- enumerable: true,
13
- get: function () {
14
- return _account[key];
15
- }
16
- });
17
- });
18
-
19
- var _instruction = require("./instruction");
20
-
21
- Object.keys(_instruction).forEach(function (key) {
22
- if (key === "default" || key === "__esModule") return;
23
- Object.defineProperty(exports, key, {
24
- enumerable: true,
25
- get: function () {
26
- return _instruction[key];
27
- }
28
- });
29
- });
30
-
31
- var _message = require("./message");
32
-
33
- Object.keys(_message).forEach(function (key) {
34
- if (key === "default" || key === "__esModule") return;
35
- Object.defineProperty(exports, key, {
36
- enumerable: true,
37
- get: function () {
38
- return _message[key];
39
- }
40
- });
41
- });
42
-
43
- var _nonceAccount = require("./nonce-account");
44
-
45
- Object.keys(_nonceAccount).forEach(function (key) {
46
- if (key === "default" || key === "__esModule") return;
47
- Object.defineProperty(exports, key, {
48
- enumerable: true,
49
- get: function () {
50
- return _nonceAccount[key];
51
- }
52
- });
53
- });
54
-
55
- var _publickey = require("./publickey");
56
-
57
- Object.keys(_publickey).forEach(function (key) {
58
- if (key === "default" || key === "__esModule") return;
59
- Object.defineProperty(exports, key, {
60
- enumerable: true,
61
- get: function () {
62
- return _publickey[key];
63
- }
64
- });
65
- });
66
-
67
- var _systemProgram = require("./system-program");
68
-
69
- Object.keys(_systemProgram).forEach(function (key) {
70
- if (key === "default" || key === "__esModule") return;
71
- Object.defineProperty(exports, key, {
72
- enumerable: true,
73
- get: function () {
74
- return _systemProgram[key];
75
- }
76
- });
77
- });
78
-
79
- var _stakeProgram = require("./stake-program");
80
-
81
- Object.keys(_stakeProgram).forEach(function (key) {
82
- if (key === "default" || key === "__esModule") return;
83
- Object.defineProperty(exports, key, {
84
- enumerable: true,
85
- get: function () {
86
- return _stakeProgram[key];
87
- }
88
- });
89
- });
90
-
91
- var _sysvar = require("./sysvar");
92
-
93
- Object.keys(_sysvar).forEach(function (key) {
94
- if (key === "default" || key === "__esModule") return;
95
- Object.defineProperty(exports, key, {
96
- enumerable: true,
97
- get: function () {
98
- return _sysvar[key];
99
- }
100
- });
101
- });
102
-
103
- var _transaction = require("./transaction");
104
-
105
- Object.keys(_transaction).forEach(function (key) {
106
- if (key === "default" || key === "__esModule") return;
107
- Object.defineProperty(exports, key, {
108
- enumerable: true,
109
- get: function () {
110
- return _transaction[key];
111
- }
112
- });
113
- });
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.encodeData = encodeData;
7
- exports.decodeData = decodeData;
8
-
9
- var BufferLayout = _interopRequireWildcard(require("@exodus/buffer-layout"));
10
-
11
- var Layout = _interopRequireWildcard(require("./utils/layout"));
12
-
13
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
14
-
15
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
-
17
- /**
18
- * Populate a buffer of instruction data using an InstructionType
19
- */
20
- function encodeData(type, fields) {
21
- const allocLength = type.layout.span >= 0 ? type.layout.span : Layout.getAlloc(type, fields);
22
- const data = Buffer.alloc(allocLength);
23
- const layoutFields = Object.assign({
24
- instruction: type.index
25
- }, fields);
26
- type.layout.encode(layoutFields, data);
27
- return data;
28
- }
29
- /**
30
- * Decode instruction data buffer using an InstructionType
31
- */
32
-
33
-
34
- function decodeData(type, buffer) {
35
- let data;
36
-
37
- try {
38
- data = type.layout.decode(buffer);
39
- } catch (err) {
40
- throw new Error('invalid instruction; ' + err);
41
- }
42
-
43
- if (data.instruction !== type.index) {
44
- throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
45
- }
46
-
47
- return data;
48
- }