Skip to content

Commit 6c486aa

Browse files
committed
Update the index logic to create AssetAddressLog records
1 parent ad46d40 commit 6c486aa

File tree

6 files changed

+36
-23
lines changed

6 files changed

+36
-23
lines changed

src/models/logic/block.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as Exception from "../../exception";
66
import { BlockInstance } from "../block";
77
import models from "../index";
88
import * as AddressLogModel from "./addressLog";
9+
import * as AssetAddressLogModel from "./assetAddressLog";
910
import * as AssetTypeLogModel from "./assetTypeLog";
1011
import * as TxModel from "./transaction";
1112
import { strip0xPrefix } from "./utils/format";
@@ -65,6 +66,7 @@ export async function createBlock(
6566
} else {
6667
await AddressLogModel.updateAddressLog(tx, options);
6768
await AssetTypeLogModel.updateAssetTypeLog(tx, options);
69+
await AssetAddressLogModel.updateAssetAddressLog(tx, options);
6870
}
6971
}
7072
await TxModel.createTransactions(

src/models/logic/increaseassetsupply.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { Transaction } from "sequelize";
1212
import { IncreaseAssetSupplyInstance } from "../increaseAssetSupply";
1313
import models from "../index";
14-
import { createAddressLog } from "./addressLog";
14+
import { createAssetAddressLog } from "./assetAddressLog";
1515
import { createAssetTransferOutput } from "./assettransferoutput";
1616
import { createAssetTypeLog } from "./assetTypeLog";
1717
import { getOwner } from "./utils/address";
@@ -66,7 +66,7 @@ export async function createIncreaseAssetSupply(
6666
options
6767
);
6868
if (recipient) {
69-
await createAddressLog(transaction, recipient, "AssetOwner", options);
69+
await createAssetAddressLog(transaction, recipient, assetType, options);
7070
}
7171
await createAssetTypeLog(transaction, assetType, options);
7272
return inst;

src/models/logic/mintAsset.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Transaction } from "sequelize";
99
import models from "../index";
1010
import { MintAssetInstance } from "../mintAsset";
1111
import { createAddressLog } from "./addressLog";
12+
import { createAssetAddressLog } from "./assetAddressLog";
1213
import { createAssetScheme } from "./assetscheme";
1314
import { createAssetTransferOutput } from "./assettransferoutput";
1415
import { createAssetTypeLog } from "./assetTypeLog";
@@ -102,15 +103,15 @@ export async function createMintAsset(
102103
{ networkId },
103104
options
104105
);
105-
await Promise.all([
106+
await Promise.all<any>([
106107
approver != null
107108
? createAddressLog(transaction, approver, "Approver", options)
108109
: Promise.resolve(null),
109110
registrar != null
110111
? createAddressLog(transaction, registrar, "Registrar", options)
111112
: Promise.resolve(null),
112113
recipient != null
113-
? createAddressLog(transaction, recipient, "AssetOwner", options)
114+
? createAssetAddressLog(transaction, recipient, assetType, options)
114115
: Promise.resolve(null),
115116
createAssetTypeLog(transaction, assetType, options)
116117
]);

src/models/logic/transferAsset.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as _ from "lodash";
1313
import { Transaction } from "sequelize";
1414
import models from "../index";
1515
import { TransferAssetInstance } from "../transferAsset";
16-
import { createAddressLog } from "./addressLog";
16+
import { createAssetAddressLog } from "./assetAddressLog";
1717
import {
1818
createAssetTransferOutput,
1919
getOutputOwner
@@ -237,12 +237,6 @@ export async function createTransferAsset(
237237
),
238238
..._.uniq(resultOutputs.filter(o => o.owner).map(o => o.owner!))
239239
]);
240-
await Promise.all(
241-
addresses.map(address =>
242-
createAddressLog(transaction, address, "AssetOwner", options)
243-
)
244-
);
245-
// FIXME: Log the addresses in orders.
246240
const assetTypes: string[] = _.uniq([
247241
..._.uniq(resultInputs.map(i => i.assetType)),
248242
..._.uniq(resultBurns.map(b => b.assetType)),
@@ -253,5 +247,25 @@ export async function createTransferAsset(
253247
createAssetTypeLog(transaction, assetType, options)
254248
)
255249
);
250+
// NOTE: TransferAsset can have many inputs and outputs, and some addresses
251+
// may not be related to a specific asset type if it's a
252+
// CoinJoin(https://en.bitcoin.it/wiki/CoinJoin) transaction. However, it
253+
// creates combinations of all the asset addresses and the asset types
254+
// because there is no clear way to tell which addresses are not related to
255+
// which asset types.
256+
await Promise.all(
257+
addresses.map(address =>
258+
Promise.all(
259+
assetTypes.map(assetType =>
260+
createAssetAddressLog(
261+
transaction,
262+
address,
263+
assetType,
264+
options
265+
)
266+
)
267+
)
268+
)
269+
);
256270
return result;
257271
}

src/models/logic/unwrapCCC.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Transaction } from "sequelize";
77
import models from "../index";
88
import { UnwrapCCCInstance } from "../unwrapCCC";
99
import { createAddressLog } from "./addressLog";
10+
import { createAssetAddressLog } from "./assetAddressLog";
1011
import { getOutputOwner } from "./assettransferoutput";
1112
import { createAssetTypeLog } from "./assetTypeLog";
1213
import { strip0xPrefix } from "./utils/format";
@@ -49,14 +50,11 @@ export async function createUnwrapCCC(
4950
},
5051
{ transaction: options.transaction }
5152
);
53+
const assetType = "0000000000000000000000000000000000000000";
5254
if (owner) {
53-
await createAddressLog(transaction, owner, "AssetOwner", options);
55+
await createAssetAddressLog(transaction, owner, assetType, options);
5456
}
5557
await createAddressLog(transaction, receiver, "AssetOwner", options);
56-
await createAssetTypeLog(
57-
transaction,
58-
"0000000000000000000000000000000000000000",
59-
options
60-
);
58+
await createAssetTypeLog(transaction, assetType, options);
6159
return instance;
6260
}

src/models/logic/wrapCCC.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Transaction } from "sequelize";
1212
import models from "../index";
1313
import { WrapCCCInstance } from "../wrapCCC";
1414
import { createAddressLog } from "./addressLog";
15+
import { createAssetAddressLog } from "./assetAddressLog";
1516
import { createAssetSchemeOfWCCC } from "./assetscheme";
1617
import { createAssetTransferOutput } from "./assettransferoutput";
1718
import { createAssetTypeLog } from "./assetTypeLog";
@@ -74,13 +75,10 @@ export async function createWrapCCC(
7475
options
7576
);
7677
await createAddressLog(transaction, payer, "AssetOwner", options);
78+
const assetType = "0000000000000000000000000000000000000000";
7779
if (recipient) {
78-
await createAddressLog(transaction, recipient, "AssetOwner", options);
80+
await createAssetAddressLog(transaction, recipient, assetType, options);
7981
}
80-
await createAssetTypeLog(
81-
transaction,
82-
"0000000000000000000000000000000000000000",
83-
options
84-
);
82+
await createAssetTypeLog(transaction, assetType, options);
8583
return result;
8684
}

0 commit comments

Comments
 (0)