Skip to content

Commit

Permalink
refactor: Bump lumos version and using exact search mode
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Apr 18, 2023
1 parent a9e6753 commit 4d92907
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 110 deletions.
6 changes: 3 additions & 3 deletions apps/godwoken-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
},
"dependencies": {
"@ant-design/icons": "^4.7.0",
"@ckb-lumos/bi": "^0.20.0-alpha.1",
"@ckb-lumos/codec": "^0.20.0-alpha.1",
"@ckb-lumos/lumos": "^0.20.0-alpha.1",
"@ckb-lumos/bi": "^0.20.0-alpha.2",
"@ckb-lumos/codec": "^0.20.0-alpha.2",
"@ckb-lumos/lumos": "^0.20.0-alpha.2",
"@metamask/detect-provider": "^1.2.0",
"@metamask/providers": "^8.1.1",
"@rehooks/local-storage": "^2.4.4",
Expand Down
2 changes: 2 additions & 0 deletions apps/godwoken-bridge/src/components/ClaimSudt/sudtFaucet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export async function generateClaimUSDCTxSkeleton(
lock: userOmniLock,
type: "empty",
outputDataLenRange: ["0x0", "0x1"],
scriptSearchMode: "exact",
});
let collectedSum = BI.from(0);
const collectedCells: Cell[] = [];
Expand All @@ -94,6 +95,7 @@ export async function generateClaimUSDCTxSkeleton(
lock: issuerLock,
type: "empty",
outputDataLenRange: ["0x0", "0x1"],
scriptSearchMode: "exact",
});
let issuerCellCapacity = BI.from(0);
for await (const cell of issuerCellCollector.collect()) {
Expand Down
8 changes: 4 additions & 4 deletions packages/light-godwoken/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"dist"
],
"dependencies": {
"@ckb-lumos/base": "^0.20.0-alpha.1",
"@ckb-lumos/bi": "^0.20.0-alpha.1",
"@ckb-lumos/codec": "^0.20.0-alpha.1",
"@ckb-lumos/lumos": "^0.20.0-alpha.1",
"@ckb-lumos/base": "^0.20.0-alpha.2",
"@ckb-lumos/bi": "^0.20.0-alpha.2",
"@ckb-lumos/codec": "^0.20.0-alpha.2",
"@ckb-lumos/lumos": "^0.20.0-alpha.2",
"@polyjuice-provider/base": "^0.1.1",
"@polyjuice-provider/ethers": "^0.1.5",
"@polyjuice-provider/godwoken": "^0.1.1",
Expand Down
15 changes: 15 additions & 0 deletions packages/light-godwoken/src/lightGodwoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default abstract class DefaultLightGodwoken implements LightGodwokenBase
debug("depositLock", depositLock);
const ckbCollector = this.provider.ckbIndexer.collector({
lock: depositLock,
scriptSearchMode: "exact",
});
const currentCkbBlockNumber = await this.getCkbCurrentBlockNumber();
const depositList: DepositRequest[] = [];
Expand Down Expand Up @@ -204,6 +205,7 @@ export default abstract class DefaultLightGodwoken implements LightGodwokenBase
lock: ownerLock,
type: "empty",
outputDataLenRange: ["0x0", "0x1"],
scriptSearchMode: "exact",
});
let ownerCellCapacity = BI.from(0);
for await (const cell of ownerCellCollector.collect()) {
Expand Down Expand Up @@ -331,6 +333,7 @@ export default abstract class DefaultLightGodwoken implements LightGodwokenBase
}),
type: "empty",
outputDataLenRange: ["0x0", "0x1"],
scriptSearchMode: "exact",
});
for await (const cell of ckbCollector.collect()) {
collectedCapacity = collectedCapacity.add(BI.from(cell.cellOutput.capacity));
Expand All @@ -343,6 +346,8 @@ export default abstract class DefaultLightGodwoken implements LightGodwokenBase
// if user don't deposit all sudt, we need to collect more capacity to exchange for sudt
neededCapacity = neededCapacity.add(BI.from(SUDT_CELL_CAPACITY));
}
// Throw https://github.com/ckb-js/lumos/blob/v0.20.0-alpha.2/packages/ckb-indexer/src/services.ts#L23-L30
// When both `lock` and `type` in search key, the script search mode will works on `lock`
const sudtCollector = this.provider.ckbIndexer.collector({
lock: helpers.parseAddress(this.provider.l1Address, {
config: this.getConfig().lumosConfig,
Expand All @@ -351,6 +356,7 @@ export default abstract class DefaultLightGodwoken implements LightGodwokenBase
// if sudt cell's data has more info than just amount (16 bytes), skip it
// because we don't know what the extension bytes contain
outputDataLenRange: ["0x10", "0x11"],
scriptSearchMode: "exact",
});
for await (const cell of sudtCollector.collect()) {
collectedCapacity = collectedCapacity.add(BI.from(cell.cellOutput.capacity));
Expand All @@ -374,6 +380,8 @@ export default abstract class DefaultLightGodwoken implements LightGodwokenBase
// if sudt cell's data has more info than just amount (16 bytes), skip it
// because we don't know what the extension bytes contain
outputDataLenRange: ["0x10", "0x11"],
// `exact` only works on lock
scriptSearchMode: "exact",
});
for await (const cell of freeCkbCollector.collect()) {
const haveFreeCapacity = BI.from(SUDT_CELL_CAPACITY).lt(cell.cellOutput.capacity);
Expand Down Expand Up @@ -926,6 +934,7 @@ export default abstract class DefaultLightGodwoken implements LightGodwokenBase
// if sudt cell's data has more info than just amount (16 bytes), skip it
// because we don't know what the extension bytes contain
outputDataLenRange: ["0x10", "0x11"],
scriptSearchMode: "exact",
});
for await (const cell of sudtCollector.collect()) {
collectedCells.push(cell);
Expand All @@ -950,6 +959,8 @@ export default abstract class DefaultLightGodwoken implements LightGodwokenBase
// if sudt cell's data has more info than just amount (16 bytes), skip it
// because we don't know what the extension bytes contain
outputDataLenRange: ["0x10", "0x11"],
// `exact` only works on lock
scriptSearchMode: "exact",
});
for await (const cell of freeCkbCollector.collect()) {
const hasFreeCkb = BI.from(cell.cellOutput.capacity).gt(SUDT_CELL_CAPACITY);
Expand All @@ -976,6 +987,7 @@ export default abstract class DefaultLightGodwoken implements LightGodwokenBase
lock: senderLock,
type: "empty",
outputDataLenRange: ["0x0", "0x1"],
scriptSearchMode: "exact",
});
for await (const cell of ckbCollector.collect()) {
collectedCkb = collectedCkb.add(BI.from(cell.cellOutput.capacity));
Expand Down Expand Up @@ -1194,6 +1206,8 @@ export default abstract class DefaultLightGodwoken implements LightGodwokenBase
// if sudt cell's data has more info than just amount (16 bytes), skip it
// because we don't know what the extension bytes contain
outputDataLenRange: ["0x10", "0x11"],
// `exact` only works on lock
scriptSearchMode: "exact",
});

// type hash list of all sudt that user want to query
Expand Down Expand Up @@ -1233,6 +1247,7 @@ export default abstract class DefaultLightGodwoken implements LightGodwokenBase
lock: fromScript,
type: "empty",
outputDataLenRange: ["0x0", "0x1"],
scriptSearchMode: "exact",
});
for await (const cell of collector.collect()) {
collectedSum = collectedSum.add(cell.cellOutput.capacity);
Expand Down
9 changes: 6 additions & 3 deletions packages/light-godwoken/src/lightGodwokenProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default class DefaultLightGodwokenProvider implements LightGodwokenProvid
}),
type: "empty",
outputDataLenRange: ["0x0", "0x1"],
scriptSearchMode: "exact",
});
for await (const cell of pureCkbCollector.collect()) {
ckbBalance = ckbBalance.add(cell.cellOutput.capacity);
Expand All @@ -132,6 +133,8 @@ export default class DefaultLightGodwokenProvider implements LightGodwokenProvid
// if sudt cell's data has more info than just amount (16 bytes), skip it
// because we don't know what the extension bytes contain
outputDataLenRange: ["0x10", "0x11"],
// `exact` only works on lock
scriptSearchMode: "exact",
});
for await (const cell of freeCkbCollector.collect()) {
ckbBalance = ckbBalance.add(cell.cellOutput.capacity).sub(SUDT_CELL_CAPACITY);
Expand Down Expand Up @@ -220,14 +223,14 @@ export default class DefaultLightGodwokenProvider implements LightGodwokenProvid

async getRollupCell(): Promise<Cell | undefined> {
const rollupConfig = this.config.layer2Config.ROLLUP_CONFIG;
const queryOptions = {
const collector = this.ckbIndexer.collector({
type: {
codeHash: rollupConfig.rollupTypeScript.codeHash,
hashType: rollupConfig.rollupTypeScript.hashType,
args: rollupConfig.rollupTypeScript.args,
},
};
const collector = this.ckbIndexer.collector(queryOptions);
scriptSearchMode: "exact",
});
let rollupCell;
for await (const cell of collector.collect()) {
if (cell === null) {
Expand Down
1 change: 1 addition & 0 deletions scripts/v0/unlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ async function main() {
code_hash: withdrawalLock.script_type_hash,
args: `${config.layer2Config.ROLLUP_CONFIG.rollup_type_hash}${targetAccountScriptHash.slice(2)}`,
},
scriptSearchMode: "exact",
});

const cells: Cell[] = [];
Expand Down
Loading

0 comments on commit 4d92907

Please sign in to comment.