@nestjs-dash/wallet 0.1.1
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/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +95 -0
- package/dist/cli.js.map +1 -0
- package/dist/entities/transaction.entity.d.ts +18 -0
- package/dist/entities/transaction.entity.d.ts.map +1 -0
- package/dist/entities/transaction.entity.js +68 -0
- package/dist/entities/transaction.entity.js.map +1 -0
- package/dist/entities/transfer.entity.d.ts +23 -0
- package/dist/entities/transfer.entity.d.ts.map +1 -0
- package/dist/entities/transfer.entity.js +97 -0
- package/dist/entities/transfer.entity.js.map +1 -0
- package/dist/entities/wallet.entity.d.ts +16 -0
- package/dist/entities/wallet.entity.d.ts.map +1 -0
- package/dist/entities/wallet.entity.js +67 -0
- package/dist/entities/wallet.entity.js.map +1 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +25 -0
- package/dist/errors.js.map +1 -0
- package/dist/events/wallet-event.publisher.d.ts +12 -0
- package/dist/events/wallet-event.publisher.d.ts.map +1 -0
- package/dist/events/wallet-event.publisher.js +44 -0
- package/dist/events/wallet-event.publisher.js.map +1 -0
- package/dist/events/wallet.events.d.ts +22 -0
- package/dist/events/wallet.events.d.ts.map +1 -0
- package/dist/events/wallet.events.js +2 -0
- package/dist/events/wallet.events.js.map +1 -0
- package/dist/exchange.service.d.ts +17 -0
- package/dist/exchange.service.d.ts.map +1 -0
- package/dist/exchange.service.js +70 -0
- package/dist/exchange.service.js.map +1 -0
- package/dist/float-wallet.service.d.ts +11 -0
- package/dist/float-wallet.service.d.ts.map +1 -0
- package/dist/float-wallet.service.js +33 -0
- package/dist/float-wallet.service.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/lock/array-lock.service.d.ts +8 -0
- package/dist/lock/array-lock.service.d.ts.map +1 -0
- package/dist/lock/array-lock.service.js +60 -0
- package/dist/lock/array-lock.service.js.map +1 -0
- package/dist/lock/lock.service.d.ts +5 -0
- package/dist/lock/lock.service.d.ts.map +1 -0
- package/dist/lock/lock.service.js +4 -0
- package/dist/lock/lock.service.js.map +1 -0
- package/dist/lock/memcached-lock.service.d.ts +21 -0
- package/dist/lock/memcached-lock.service.d.ts.map +1 -0
- package/dist/lock/memcached-lock.service.js +45 -0
- package/dist/lock/memcached-lock.service.js.map +1 -0
- package/dist/lock/redis-lock.service.d.ts +13 -0
- package/dist/lock/redis-lock.service.d.ts.map +1 -0
- package/dist/lock/redis-lock.service.js +43 -0
- package/dist/lock/redis-lock.service.js.map +1 -0
- package/dist/migrations/generate.d.ts +22 -0
- package/dist/migrations/generate.d.ts.map +1 -0
- package/dist/migrations/generate.js +226 -0
- package/dist/migrations/generate.js.map +1 -0
- package/dist/tokens.d.ts +56 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +13 -0
- package/dist/tokens.js.map +1 -0
- package/dist/transfer.service.d.ts +29 -0
- package/dist/transfer.service.d.ts.map +1 -0
- package/dist/transfer.service.js +154 -0
- package/dist/transfer.service.js.map +1 -0
- package/dist/wallet.module.d.ts +12 -0
- package/dist/wallet.module.d.ts.map +1 -0
- package/dist/wallet.module.js +150 -0
- package/dist/wallet.module.js.map +1 -0
- package/dist/wallet.service.d.ts +39 -0
- package/dist/wallet.service.d.ts.map +1 -0
- package/dist/wallet.service.js +230 -0
- package/dist/wallet.service.js.map +1 -0
- package/dist/warmup.service.d.ts +13 -0
- package/dist/warmup.service.d.ts.map +1 -0
- package/dist/warmup.service.js +76 -0
- package/dist/warmup.service.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
export const DEFAULT_TABLES = {
|
|
2
|
+
wallets: 'wallets',
|
|
3
|
+
transactions: 'transactions',
|
|
4
|
+
transfers: 'transfers',
|
|
5
|
+
};
|
|
6
|
+
function stamp(base, index) {
|
|
7
|
+
return String(base + index);
|
|
8
|
+
}
|
|
9
|
+
export function buildMigrationClassName(suffix, stampValue) {
|
|
10
|
+
const pascal = suffix
|
|
11
|
+
.split('-')
|
|
12
|
+
.map((p) => p.charAt(0).toUpperCase() + p.slice(1))
|
|
13
|
+
.join('');
|
|
14
|
+
return `Wallet${pascal}${stampValue}`;
|
|
15
|
+
}
|
|
16
|
+
export const MIGRATION_SPECS = [
|
|
17
|
+
{
|
|
18
|
+
key: 'create-transactions',
|
|
19
|
+
fileSuffix: 'create-transactions',
|
|
20
|
+
contents: (t, className) => `import { type MigrationInterface, type QueryRunner, Table, TableIndex } from 'typeorm';
|
|
21
|
+
|
|
22
|
+
export class ${className} implements MigrationInterface {
|
|
23
|
+
name = '${className}';
|
|
24
|
+
|
|
25
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
26
|
+
await queryRunner.createTable(
|
|
27
|
+
new Table({
|
|
28
|
+
name: '${t.transactions}',
|
|
29
|
+
columns: [
|
|
30
|
+
{ name: 'id', type: 'bigint', isPrimary: true, isGenerated: true, generationStrategy: 'increment' },
|
|
31
|
+
{ name: 'payable_type', type: 'varchar', length: '255' },
|
|
32
|
+
{ name: 'payable_id', type: 'bigint' },
|
|
33
|
+
{ name: 'wallet_id', type: 'bigint', isNullable: true },
|
|
34
|
+
{ name: 'type', type: 'enum', enum: ['deposit', 'withdraw'] },
|
|
35
|
+
{ name: 'amount', type: 'decimal', precision: 64, scale: 0 },
|
|
36
|
+
{ name: 'confirmed', type: 'boolean' },
|
|
37
|
+
{ name: 'meta', type: 'json', isNullable: true },
|
|
38
|
+
{ name: 'uuid', type: 'char', length: '36', isUnique: true },
|
|
39
|
+
{ name: 'created_at', type: 'timestamp', default: 'CURRENT_TIMESTAMP' },
|
|
40
|
+
{ name: 'updated_at', type: 'timestamp', default: 'CURRENT_TIMESTAMP' },
|
|
41
|
+
],
|
|
42
|
+
}),
|
|
43
|
+
true,
|
|
44
|
+
);
|
|
45
|
+
await queryRunner.createIndex(
|
|
46
|
+
'${t.transactions}',
|
|
47
|
+
new TableIndex({ name: 'IDX_${t.transactions}_payable', columnNames: ['payable_type', 'payable_id'] }),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
52
|
+
await queryRunner.dropTable('${t.transactions}');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
`,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
key: 'create-transfers',
|
|
59
|
+
fileSuffix: 'create-transfers',
|
|
60
|
+
contents: (t, className) => `import { type MigrationInterface, type QueryRunner, Table } from 'typeorm';
|
|
61
|
+
|
|
62
|
+
export class ${className} implements MigrationInterface {
|
|
63
|
+
name = '${className}';
|
|
64
|
+
|
|
65
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
66
|
+
await queryRunner.createTable(
|
|
67
|
+
new Table({
|
|
68
|
+
name: '${t.transfers}',
|
|
69
|
+
columns: [
|
|
70
|
+
{ name: 'id', type: 'bigint', isPrimary: true, isGenerated: true, generationStrategy: 'increment' },
|
|
71
|
+
{ name: 'from_type', type: 'varchar', length: '255' },
|
|
72
|
+
{ name: 'from_id', type: 'bigint' },
|
|
73
|
+
{ name: 'to_type', type: 'varchar', length: '255' },
|
|
74
|
+
{ name: 'to_id', type: 'bigint' },
|
|
75
|
+
{ name: 'status', type: 'enum', enum: ['exchange', 'transfer', 'paid', 'refund', 'gift'], default: "'transfer'" },
|
|
76
|
+
{ name: 'status_last', type: 'enum', enum: ['exchange', 'transfer', 'paid', 'refund', 'gift'], isNullable: true },
|
|
77
|
+
{ name: 'deposit_id', type: 'bigint' },
|
|
78
|
+
{ name: 'withdraw_id', type: 'bigint' },
|
|
79
|
+
{ name: 'discount', type: 'decimal', precision: 64, scale: 0, default: 0 },
|
|
80
|
+
{ name: 'fee', type: 'decimal', precision: 64, scale: 0, default: 0 },
|
|
81
|
+
{ name: 'uuid', type: 'char', length: '36', isUnique: true },
|
|
82
|
+
{ name: 'created_at', type: 'timestamp', default: 'CURRENT_TIMESTAMP' },
|
|
83
|
+
{ name: 'updated_at', type: 'timestamp', default: 'CURRENT_TIMESTAMP' },
|
|
84
|
+
],
|
|
85
|
+
foreignKeys: [
|
|
86
|
+
{ columnNames: ['deposit_id'], referencedTableName: '${t.transactions}', referencedColumnNames: ['id'] },
|
|
87
|
+
{ columnNames: ['withdraw_id'], referencedTableName: '${t.transactions}', referencedColumnNames: ['id'] },
|
|
88
|
+
],
|
|
89
|
+
}),
|
|
90
|
+
true,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
95
|
+
await queryRunner.dropTable('${t.transfers}');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
`,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
key: 'create-wallets',
|
|
102
|
+
fileSuffix: 'create-wallets',
|
|
103
|
+
contents: (t, className) => `import { type MigrationInterface, type QueryRunner, Table, TableForeignKey, TableIndex, TableUnique } from 'typeorm';
|
|
104
|
+
|
|
105
|
+
export class ${className} implements MigrationInterface {
|
|
106
|
+
name = '${className}';
|
|
107
|
+
|
|
108
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
109
|
+
await queryRunner.createTable(
|
|
110
|
+
new Table({
|
|
111
|
+
name: '${t.wallets}',
|
|
112
|
+
columns: [
|
|
113
|
+
{ name: 'id', type: 'bigint', isPrimary: true, isGenerated: true, generationStrategy: 'increment' },
|
|
114
|
+
{ name: 'holder_type', type: 'varchar', length: '255' },
|
|
115
|
+
{ name: 'holder_id', type: 'bigint' },
|
|
116
|
+
{ name: 'name', type: 'varchar', length: '255' },
|
|
117
|
+
{ name: 'slug', type: 'varchar', length: '255' },
|
|
118
|
+
{ name: 'uuid', type: 'char', length: '36', isUnique: true },
|
|
119
|
+
{ name: 'description', type: 'varchar', length: '255', isNullable: true },
|
|
120
|
+
{ name: 'meta', type: 'json', isNullable: true },
|
|
121
|
+
{ name: 'balance', type: 'decimal', precision: 64, scale: 0, default: 0 },
|
|
122
|
+
{ name: 'decimal_places', type: 'smallint', unsigned: true, default: 2 },
|
|
123
|
+
{ name: 'created_at', type: 'timestamp', default: 'CURRENT_TIMESTAMP' },
|
|
124
|
+
{ name: 'updated_at', type: 'timestamp', default: 'CURRENT_TIMESTAMP' },
|
|
125
|
+
],
|
|
126
|
+
}),
|
|
127
|
+
true,
|
|
128
|
+
);
|
|
129
|
+
await queryRunner.createUniqueConstraint(
|
|
130
|
+
'${t.wallets}',
|
|
131
|
+
new TableUnique({ name: 'UNQ_${t.wallets}_holder_slug', columnNames: ['holder_type', 'holder_id', 'slug'] }),
|
|
132
|
+
);
|
|
133
|
+
await queryRunner.createIndex(
|
|
134
|
+
'${t.wallets}',
|
|
135
|
+
new TableIndex({ name: 'IDX_${t.wallets}_slug', columnNames: ['slug'] }),
|
|
136
|
+
);
|
|
137
|
+
await queryRunner.createForeignKey(
|
|
138
|
+
'${t.transactions}',
|
|
139
|
+
new TableForeignKey({
|
|
140
|
+
columnNames: ['wallet_id'],
|
|
141
|
+
referencedTableName: '${t.wallets}',
|
|
142
|
+
referencedColumnNames: ['id'],
|
|
143
|
+
onDelete: 'CASCADE',
|
|
144
|
+
}),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
149
|
+
const table = await queryRunner.getTable('${t.transactions}');
|
|
150
|
+
const fk = table?.foreignKeys.find((f) => f.columnNames.includes('wallet_id'));
|
|
151
|
+
if (fk) await queryRunner.dropForeignKey('${t.transactions}', fk);
|
|
152
|
+
await queryRunner.dropTable('${t.wallets}');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
`,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
key: 'add-transfer-extra',
|
|
159
|
+
fileSuffix: 'add-transfer-extra',
|
|
160
|
+
contents: (t, className) => `import { type MigrationInterface, type QueryRunner, TableColumn } from 'typeorm';
|
|
161
|
+
|
|
162
|
+
export class ${className} implements MigrationInterface {
|
|
163
|
+
name = '${className}';
|
|
164
|
+
|
|
165
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
166
|
+
await queryRunner.addColumn(
|
|
167
|
+
'${t.transfers}',
|
|
168
|
+
new TableColumn({ name: 'extra', type: 'json', isNullable: true }),
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
173
|
+
await queryRunner.dropColumn('${t.transfers}', 'extra');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
`,
|
|
177
|
+
},
|
|
178
|
+
];
|
|
179
|
+
export const UUID_MIGRATION_SPEC = {
|
|
180
|
+
key: 'morph-ids-to-uuid',
|
|
181
|
+
fileSuffix: 'morph-ids-to-uuid',
|
|
182
|
+
contents: (t, className) => {
|
|
183
|
+
const q = (table, col, type) => ` await queryRunner.query("ALTER TABLE ${table} MODIFY ${col} ${type} NOT NULL");`;
|
|
184
|
+
return [
|
|
185
|
+
"import { type MigrationInterface, type QueryRunner } from 'typeorm';",
|
|
186
|
+
'',
|
|
187
|
+
`export class ${className} implements MigrationInterface {`,
|
|
188
|
+
` name = '${className}';`,
|
|
189
|
+
'',
|
|
190
|
+
' public async up(queryRunner: QueryRunner): Promise<void> {',
|
|
191
|
+
q(t.wallets, 'holder_id', 'CHAR(36)'),
|
|
192
|
+
q(t.transactions, 'payable_id', 'CHAR(36)'),
|
|
193
|
+
q(t.transfers, 'from_id', 'CHAR(36)'),
|
|
194
|
+
q(t.transfers, 'to_id', 'CHAR(36)'),
|
|
195
|
+
' }',
|
|
196
|
+
'',
|
|
197
|
+
' public async down(queryRunner: QueryRunner): Promise<void> {',
|
|
198
|
+
q(t.wallets, 'holder_id', 'BIGINT'),
|
|
199
|
+
q(t.transactions, 'payable_id', 'BIGINT'),
|
|
200
|
+
q(t.transfers, 'from_id', 'BIGINT'),
|
|
201
|
+
q(t.transfers, 'to_id', 'BIGINT'),
|
|
202
|
+
' }',
|
|
203
|
+
'}',
|
|
204
|
+
'',
|
|
205
|
+
].join('\n');
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
export function resolveTables(overrides) {
|
|
209
|
+
return { ...DEFAULT_TABLES, ...overrides };
|
|
210
|
+
}
|
|
211
|
+
export function listMigrationSpecs(withUuid = false) {
|
|
212
|
+
return withUuid ? [...MIGRATION_SPECS, UUID_MIGRATION_SPEC] : [...MIGRATION_SPECS];
|
|
213
|
+
}
|
|
214
|
+
export function generateMigrationFiles(tables, withUuid = false, baseStamp = Date.now()) {
|
|
215
|
+
return listMigrationSpecs(withUuid).map((spec, index) => {
|
|
216
|
+
const stampValue = stamp(baseStamp, index);
|
|
217
|
+
const className = buildMigrationClassName(spec.fileSuffix, stampValue);
|
|
218
|
+
const fileName = `${stampValue}-${spec.fileSuffix}.ts`;
|
|
219
|
+
return {
|
|
220
|
+
key: spec.key,
|
|
221
|
+
fileName,
|
|
222
|
+
contents: spec.contents(tables, className),
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/migrations/generate.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,cAAc,GAAwB;IACjD,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,cAAc;IAC5B,SAAS,EAAE,WAAW;CACvB,CAAC;AAQF,SAAS,KAAK,CAAC,IAAY,EAAE,KAAa;IACxC,OAAO,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,MAAc,EAAE,UAAkB;IACxE,MAAM,MAAM,GAAG,MAAM;SA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Q,CAAC;YACnC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC;YACjC,KAAK;YACL,GAAG;YACH,EAAE;SACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACf,CAAC;CACF,CAAC;AAEF,MAAM,UAAU,aAAa,CAAC,SAAwC;IACpE,OAAO,EAAE,GAAG,cAAc,EAAE,GAAG,SAAS,EAAE,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,QAAQ,GAAG,KAAK;IACjD,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,MAA2B,EAC3B,QAAQ,GAAG,KAAK,EAChB,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE;IAEtB,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACtD,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,SAAS,GAAG,uBAAuB,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QACvE,MAAM,QAAQ,GAAG,GAAG,UAAU,IAAI,IAAI,CAAC,UAAU,KAAK,CAAC;QACvD,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,QAAQ;YACR,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;SAC3C,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/tokens.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { InjectionToken } from '@nestjs/common';
|
|
2
|
+
export type HolderId = number | string;
|
|
3
|
+
export type LockDriver = 'array' | 'redis' | 'memcached';
|
|
4
|
+
export type HolderIdType = 'int' | 'uuid';
|
|
5
|
+
export interface WalletTableNames {
|
|
6
|
+
wallets?: string;
|
|
7
|
+
transactions?: string;
|
|
8
|
+
transfers?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface WalletLockOptions {
|
|
11
|
+
driver?: LockDriver;
|
|
12
|
+
ttlMs?: number;
|
|
13
|
+
redis?: {
|
|
14
|
+
url?: string;
|
|
15
|
+
};
|
|
16
|
+
memcached?: {
|
|
17
|
+
servers?: string[];
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Host TypeORM DataSource. Kept as `unknown` so pnpm duplicate `typeorm`
|
|
22
|
+
* copies do not cause cross-package assignability errors at the app boundary.
|
|
23
|
+
*/
|
|
24
|
+
export type WalletDataSourceLike = unknown;
|
|
25
|
+
export interface WalletModuleOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Host app DataSource. Required so wallet services work across pnpm
|
|
28
|
+
* duplicate `typeorm` instances (class-token injection would otherwise fail).
|
|
29
|
+
* Prefer `WalletModule.forRootAsync({ inject: [DataSource], useFactory: (ds) => ({ dataSource: ds }) })`.
|
|
30
|
+
*/
|
|
31
|
+
dataSource?: WalletDataSourceLike;
|
|
32
|
+
defaultWalletSlug?: string;
|
|
33
|
+
defaultWalletName?: string;
|
|
34
|
+
tables?: WalletTableNames;
|
|
35
|
+
holderIdType?: HolderIdType;
|
|
36
|
+
events?: {
|
|
37
|
+
enabled?: boolean;
|
|
38
|
+
};
|
|
39
|
+
exchange?: {
|
|
40
|
+
rates?: Record<string, Record<string, number>>;
|
|
41
|
+
};
|
|
42
|
+
lock?: WalletLockOptions;
|
|
43
|
+
}
|
|
44
|
+
export declare const WALLET_OPTIONS: InjectionToken;
|
|
45
|
+
export declare const WALLET_LOCK: InjectionToken;
|
|
46
|
+
/** Bridged host DataSource (avoids Nest class-token mismatch with duplicate typeorm copies). */
|
|
47
|
+
export declare const WALLET_DATA_SOURCE: InjectionToken;
|
|
48
|
+
export declare const DEFAULT_WALLET_SLUG = "default";
|
|
49
|
+
export declare const DEFAULT_WALLET_NAME = "Default Wallet";
|
|
50
|
+
export declare const DEFAULT_LOCK_TTL_MS = 3000;
|
|
51
|
+
export declare const WALLET_EVENT: {
|
|
52
|
+
readonly WALLET_CREATED: "wallet.wallet_created";
|
|
53
|
+
readonly TRANSACTION_CREATED: "wallet.transaction_created";
|
|
54
|
+
readonly BALANCE_UPDATED: "wallet.balance_updated";
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,WAAW,CAAC;AAEzD,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,MAAM,CAAC;AAE1C,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,SAAS,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CACpC;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC;AAE3C,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,MAAM,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAC/B,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;KAChD,CAAC;IACF,IAAI,CAAC,EAAE,iBAAiB,CAAC;CAC1B;AAED,eAAO,MAAM,cAAc,EAAE,cAAyC,CAAC;AACvE,eAAO,MAAM,WAAW,EAAE,cAAsC,CAAC;AACjE,gGAAgG;AAChG,eAAO,MAAM,kBAAkB,EAAE,cAA6C,CAAC;AAE/E,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAC7C,eAAO,MAAM,mBAAmB,mBAAmB,CAAC;AACpD,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC,eAAO,MAAM,YAAY;;;;CAIf,CAAC"}
|
package/dist/tokens.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const WALLET_OPTIONS = Symbol('WALLET_OPTIONS');
|
|
2
|
+
export const WALLET_LOCK = Symbol('WALLET_LOCK');
|
|
3
|
+
/** Bridged host DataSource (avoids Nest class-token mismatch with duplicate typeorm copies). */
|
|
4
|
+
export const WALLET_DATA_SOURCE = Symbol('WALLET_DATA_SOURCE');
|
|
5
|
+
export const DEFAULT_WALLET_SLUG = 'default';
|
|
6
|
+
export const DEFAULT_WALLET_NAME = 'Default Wallet';
|
|
7
|
+
export const DEFAULT_LOCK_TTL_MS = 3000;
|
|
8
|
+
export const WALLET_EVENT = {
|
|
9
|
+
WALLET_CREATED: 'wallet.wallet_created',
|
|
10
|
+
TRANSACTION_CREATED: 'wallet.transaction_created',
|
|
11
|
+
BALANCE_UPDATED: 'wallet.balance_updated',
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AA6CA,MAAM,CAAC,MAAM,cAAc,GAAmB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACvE,MAAM,CAAC,MAAM,WAAW,GAAmB,MAAM,CAAC,aAAa,CAAC,CAAC;AACjE,gGAAgG;AAChG,MAAM,CAAC,MAAM,kBAAkB,GAAmB,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAE/E,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAC7C,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AACpD,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAExC,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,cAAc,EAAE,uBAAuB;IACvC,mBAAmB,EAAE,4BAA4B;IACjD,eAAe,EAAE,wBAAwB;CACjC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DataSource } from 'typeorm';
|
|
2
|
+
import { TransferEntity, type TransferStatus } from './entities/transfer.entity.js';
|
|
3
|
+
import { WalletEntity } from './entities/wallet.entity.js';
|
|
4
|
+
import { WalletEventPublisher } from './events/wallet-event.publisher.js';
|
|
5
|
+
import { type WalletLockService } from './lock/lock.service.js';
|
|
6
|
+
import { type WalletModuleOptions } from './tokens.js';
|
|
7
|
+
import { WalletService } from './wallet.service.js';
|
|
8
|
+
export interface TransferOptions {
|
|
9
|
+
fee?: number | string;
|
|
10
|
+
discount?: number | string;
|
|
11
|
+
meta?: Record<string, unknown> | null;
|
|
12
|
+
extra?: Record<string, unknown> | null;
|
|
13
|
+
status?: TransferStatus;
|
|
14
|
+
depositAmount?: number | string;
|
|
15
|
+
}
|
|
16
|
+
export declare class TransferService {
|
|
17
|
+
private readonly dataSource;
|
|
18
|
+
private readonly walletService;
|
|
19
|
+
private readonly lockService;
|
|
20
|
+
private readonly events;
|
|
21
|
+
private readonly lockTtlMs;
|
|
22
|
+
constructor(dataSource: DataSource, walletService: WalletService, options: WalletModuleOptions, lockService: WalletLockService, events: WalletEventPublisher);
|
|
23
|
+
transfer(from: WalletEntity, to: WalletEntity, amount: number | string, options?: TransferOptions): Promise<TransferEntity>;
|
|
24
|
+
transferFloat(from: WalletEntity, to: WalletEntity, amount: number, options?: Omit<TransferOptions, 'fee' | 'discount' | 'depositAmount'> & {
|
|
25
|
+
fee?: number;
|
|
26
|
+
discount?: number;
|
|
27
|
+
}): Promise<TransferEntity>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=transfer.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.service.d.ts","sourceRoot":"","sources":["../src/transfer.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,KAAK,iBAAiB,EAAiB,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAKL,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACvC,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACjC;AAED,qBACa,eAAe;IAKxB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAET,OAAO,CAAC,QAAQ,CAAC,WAAW;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM;IARzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAIhB,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,EACrB,OAAO,EAAE,mBAAmB,EACd,WAAW,EAAE,iBAAiB,EACnD,MAAM,EAAE,oBAAoB;IAKzC,QAAQ,CACZ,IAAI,EAAE,YAAY,EAClB,EAAE,EAAE,YAAY,EAChB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,cAAc,CAAC;IAiHpB,aAAa,CACjB,IAAI,EAAE,YAAY,EAClB,EAAE,EAAE,YAAY,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,IAAI,CAAC,eAAe,EAAE,KAAK,GAAG,UAAU,GAAG,eAAe,CAAC,GAAG;QACrE,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;KACd,GACL,OAAO,CAAC,cAAc,CAAC;CAgB3B"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Inject, Injectable } from '@nestjs/common';
|
|
14
|
+
import { randomUUID } from 'node:crypto';
|
|
15
|
+
import { DataSource } from 'typeorm';
|
|
16
|
+
import { TransactionEntity } from './entities/transaction.entity.js';
|
|
17
|
+
import { TransferEntity } from './entities/transfer.entity.js';
|
|
18
|
+
import { WalletEntity } from './entities/wallet.entity.js';
|
|
19
|
+
import { InsufficientFundsError, WalletNotFoundError } from './errors.js';
|
|
20
|
+
import { WalletEventPublisher } from './events/wallet-event.publisher.js';
|
|
21
|
+
import { walletLockKey } from './lock/lock.service.js';
|
|
22
|
+
import { DEFAULT_LOCK_TTL_MS, WALLET_DATA_SOURCE, WALLET_LOCK, WALLET_OPTIONS, } from './tokens.js';
|
|
23
|
+
import { WalletService } from './wallet.service.js';
|
|
24
|
+
let TransferService = class TransferService {
|
|
25
|
+
constructor(dataSource, walletService, options, lockService, events) {
|
|
26
|
+
this.dataSource = dataSource;
|
|
27
|
+
this.walletService = walletService;
|
|
28
|
+
this.lockService = lockService;
|
|
29
|
+
this.events = events;
|
|
30
|
+
this.lockTtlMs = options.lock?.ttlMs ?? DEFAULT_LOCK_TTL_MS;
|
|
31
|
+
}
|
|
32
|
+
async transfer(from, to, amount, options = {}) {
|
|
33
|
+
const withdrawAmount = this.walletService.normalizeAmount(amount);
|
|
34
|
+
const depositAmount = this.walletService.normalizeAmount(options.depositAmount ?? amount);
|
|
35
|
+
const fee = this.walletService.normalizeAmount(options.fee ?? 0);
|
|
36
|
+
const discount = this.walletService.normalizeAmount(options.discount ?? 0);
|
|
37
|
+
if (withdrawAmount <= 0n)
|
|
38
|
+
throw new Error('Transfer amount must be positive');
|
|
39
|
+
const [firstId, secondId] = Number(from.id) < Number(to.id) ? [from.id, to.id] : [to.id, from.id];
|
|
40
|
+
return this.lockService.lock(walletLockKey(firstId), this.lockTtlMs, async () => {
|
|
41
|
+
return this.lockService.lock(walletLockKey(secondId), this.lockTtlMs, async () => {
|
|
42
|
+
return this.dataSource.transaction(async (manager) => {
|
|
43
|
+
const lockedFrom = await manager.findOne(WalletEntity, {
|
|
44
|
+
where: { id: from.id },
|
|
45
|
+
lock: { mode: 'pessimistic_write' },
|
|
46
|
+
});
|
|
47
|
+
const lockedTo = await manager.findOne(WalletEntity, {
|
|
48
|
+
where: { id: to.id },
|
|
49
|
+
lock: { mode: 'pessimistic_write' },
|
|
50
|
+
});
|
|
51
|
+
if (!lockedFrom || !lockedTo)
|
|
52
|
+
throw new WalletNotFoundError();
|
|
53
|
+
const fromOld = lockedFrom.balance;
|
|
54
|
+
const toOld = lockedTo.balance;
|
|
55
|
+
if (BigInt(lockedFrom.balance) < withdrawAmount) {
|
|
56
|
+
throw new InsufficientFundsError();
|
|
57
|
+
}
|
|
58
|
+
lockedFrom.balance = (BigInt(lockedFrom.balance) - withdrawAmount).toString();
|
|
59
|
+
lockedTo.balance = (BigInt(lockedTo.balance) + depositAmount).toString();
|
|
60
|
+
await manager.save([lockedFrom, lockedTo]);
|
|
61
|
+
const withdrawTx = await manager.save(manager.create(TransactionEntity, {
|
|
62
|
+
payableType: lockedFrom.holderType,
|
|
63
|
+
payableId: lockedFrom.holderId,
|
|
64
|
+
walletId: lockedFrom.id,
|
|
65
|
+
type: 'withdraw',
|
|
66
|
+
amount: withdrawAmount.toString(),
|
|
67
|
+
confirmed: true,
|
|
68
|
+
meta: options.meta ?? null,
|
|
69
|
+
uuid: randomUUID(),
|
|
70
|
+
}));
|
|
71
|
+
const depositTx = await manager.save(manager.create(TransactionEntity, {
|
|
72
|
+
payableType: lockedTo.holderType,
|
|
73
|
+
payableId: lockedTo.holderId,
|
|
74
|
+
walletId: lockedTo.id,
|
|
75
|
+
type: 'deposit',
|
|
76
|
+
amount: depositAmount.toString(),
|
|
77
|
+
confirmed: true,
|
|
78
|
+
meta: options.meta ?? null,
|
|
79
|
+
uuid: randomUUID(),
|
|
80
|
+
}));
|
|
81
|
+
const transfer = await manager.save(manager.create(TransferEntity, {
|
|
82
|
+
fromType: lockedFrom.holderType,
|
|
83
|
+
fromId: lockedFrom.holderId,
|
|
84
|
+
toType: lockedTo.holderType,
|
|
85
|
+
toId: lockedTo.holderId,
|
|
86
|
+
status: options.status ?? 'transfer',
|
|
87
|
+
statusLast: null,
|
|
88
|
+
depositId: depositTx.id,
|
|
89
|
+
withdrawId: withdrawTx.id,
|
|
90
|
+
discount: discount.toString(),
|
|
91
|
+
fee: fee.toString(),
|
|
92
|
+
extra: options.extra ?? null,
|
|
93
|
+
uuid: randomUUID(),
|
|
94
|
+
}));
|
|
95
|
+
this.events.transactionCreated({
|
|
96
|
+
transactionId: Number(withdrawTx.id),
|
|
97
|
+
walletId: Number(lockedFrom.id),
|
|
98
|
+
type: 'withdraw',
|
|
99
|
+
amount: withdrawTx.amount,
|
|
100
|
+
uuid: withdrawTx.uuid,
|
|
101
|
+
});
|
|
102
|
+
this.events.transactionCreated({
|
|
103
|
+
transactionId: Number(depositTx.id),
|
|
104
|
+
walletId: Number(lockedTo.id),
|
|
105
|
+
type: 'deposit',
|
|
106
|
+
amount: depositTx.amount,
|
|
107
|
+
uuid: depositTx.uuid,
|
|
108
|
+
});
|
|
109
|
+
this.events.balanceUpdated({
|
|
110
|
+
walletId: Number(lockedFrom.id),
|
|
111
|
+
holderType: lockedFrom.holderType,
|
|
112
|
+
holderId: lockedFrom.holderId,
|
|
113
|
+
balance: lockedFrom.balance,
|
|
114
|
+
oldBalance: fromOld,
|
|
115
|
+
});
|
|
116
|
+
this.events.balanceUpdated({
|
|
117
|
+
walletId: Number(lockedTo.id),
|
|
118
|
+
holderType: lockedTo.holderType,
|
|
119
|
+
holderId: lockedTo.holderId,
|
|
120
|
+
balance: lockedTo.balance,
|
|
121
|
+
oldBalance: toOld,
|
|
122
|
+
});
|
|
123
|
+
Object.assign(from, lockedFrom);
|
|
124
|
+
Object.assign(to, lockedTo);
|
|
125
|
+
return transfer;
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async transferFloat(from, to, amount, options = {}) {
|
|
131
|
+
const withdrawInt = this.walletService.floatToInt(amount, from.decimalPlaces);
|
|
132
|
+
const depositInt = this.walletService.floatToInt(amount, to.decimalPlaces);
|
|
133
|
+
return this.transfer(from, to, withdrawInt.toString(), {
|
|
134
|
+
...options,
|
|
135
|
+
depositAmount: depositInt.toString(),
|
|
136
|
+
fee: options.fee != null
|
|
137
|
+
? this.walletService.floatToInt(options.fee, from.decimalPlaces).toString()
|
|
138
|
+
: undefined,
|
|
139
|
+
discount: options.discount != null
|
|
140
|
+
? this.walletService.floatToInt(options.discount, from.decimalPlaces).toString()
|
|
141
|
+
: undefined,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
TransferService = __decorate([
|
|
146
|
+
Injectable(),
|
|
147
|
+
__param(0, Inject(WALLET_DATA_SOURCE)),
|
|
148
|
+
__param(2, Inject(WALLET_OPTIONS)),
|
|
149
|
+
__param(3, Inject(WALLET_LOCK)),
|
|
150
|
+
__metadata("design:paramtypes", [DataSource,
|
|
151
|
+
WalletService, Object, Object, WalletEventPublisher])
|
|
152
|
+
], TransferService);
|
|
153
|
+
export { TransferService };
|
|
154
|
+
//# sourceMappingURL=transfer.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.service.js","sourceRoot":"","sources":["../src/transfer.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,UA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AAQ,EAAE,EAAE;YACrD,GAAG,OAAO;YACV,aAAa,EAAE,UAAU,CAAC,QAAQ,EAAE;YACpC,GAAG,EACD,OAAO,CAAC,GAAG,IAAI,IAAI;gBACjB,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,QAAQ,EAAE;gBAC3E,CAAC,CAAC,SAAS;YACf,QAAQ,EACN,OAAO,CAAC,QAAQ,IAAI,IAAI;gBACtB,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,QAAQ,EAAE;gBAChF,CAAC,CAAC,SAAS;SAChB,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA5JY,eAAe;IAD3B,UAAU,EAAE;IAKR,WAAA,MAAM,CAAC,kBAAkB,CAAC,CAAA;IAG1B,WAAA,MAAM,CAAC,cAAc,CAAC,CAAA;IACtB,WAAA,MAAM,CAAC,WAAW,CAAC,CAAA;qCAHS,UAAU;QACP,aAAa,kBAGpB,oBAAoB;GATpC,eAAe,CA4J3B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { type WalletModuleOptions } from './tokens.js';
|
|
3
|
+
export type WalletModuleAsyncOptions = {
|
|
4
|
+
imports?: DynamicModule['imports'];
|
|
5
|
+
inject?: any[];
|
|
6
|
+
useFactory: (...args: any[]) => WalletModuleOptions | Promise<WalletModuleOptions>;
|
|
7
|
+
};
|
|
8
|
+
export declare class WalletModule {
|
|
9
|
+
static forRoot(options?: WalletModuleOptions): DynamicModule;
|
|
10
|
+
static forRootAsync(options: WalletModuleAsyncOptions): DynamicModule;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=wallet.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.module.d.ts","sourceRoot":"","sources":["../src/wallet.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAyB,MAAM,gBAAgB,CAAC;AAa3E,OAAO,EAQL,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AAKrB,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IAGnC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;IAEf,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACpF,CAAC;AAqGF,qBACa,YAAY;IACvB,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,mBAAwB,GAAG,aAAa;IAgBhE,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa;CAiBtE"}
|