-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ownership provider to work with Lumos #127
Conversation
Signed-off-by: homura <[email protected]>
Signed-off-by: homura <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #127 +/- ##
==========================================
- Coverage 87.25% 86.20% -1.05%
==========================================
Files 48 43 -5
Lines 816 870 +54
Branches 97 113 +16
==========================================
+ Hits 712 750 +38
+ Misses 21 20 -1
- Partials 83 100 +17
... and 14 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
import produce from 'immer'; | ||
|
||
declare const recipient: Script; | ||
declare const provider: FullOwnershipProvider; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to get the provider instance? it seems to be:
const provider = new FullOwnershipProvider(globalThis.ckb)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new FullOwnershipProvider({ ckb: globalThis.ckb })
we can check out from FullOwnershipProvider.ts
import { BIish } from '@ckb-lumos/bi'; | ||
import produce from 'immer'; | ||
|
||
declare const recipient: Script; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An idea: a test case can be based on this example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, this example is suitable as a case for integration testing, but I think it may be less suitable as a unit test case
I want to reuse lumos prepare signing entries method. Thus, my code will seems like /**
* request wallet to sign a transaction skeleton
* @param txSkeleton The transaction skeleton, you can create it from transaction object via `@ckb-lumos` {@link createTransactionFromSkeleton}
* @returns The signed transaction skeleton. To get the signed transaction object, please use {@link sealTransaction} with empty sealingContents(`[ ]`).
*/
async signTransaction(txSkeleton: TransactionSkeletonType): Promise<TransactionSkeletonType> {
const config = getConfigFromRpcUrl();
prepareSigningEntries(txSkeleton, config);
const groupedSignature = await this.ckb.request({
method: 'wallet_fullOwnership_signTransaction',
params: { tx: createTransactionFromSkeleton(txSkeleton) },
});
txSkeleton = txSkeleton.update('witnesses', (witnesses) => {
return witnesses.map((witness, index) => {
const [, signature] = groupedSignature[index];
if (!signature) return witness;
const witnessArgs = WitnessArgs.unpack(witness);
return bytes.hexify(
WitnessArgs.pack({
...witnessArgs,
lock: signature,
}),
);
});
});
txSkeleton = txSkeleton.update('signingEntries', (signingEntries) =>
signingEntries.splice(0, groupedSignature.length),
);
return txSkeleton;
} |
}); | ||
}); | ||
|
||
txSkeleton = txSkeleton.update('signingEntries', (signingEntries) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to clear signingEntries here
return txSkeletonWithFee; | ||
} | ||
|
||
async *collector({ lock }: { lock?: Script } = {}): AsyncIterable<Cell> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pro usage, not easy to understand though
Insufficient coverage of unit tests, can you add tests? |
<line num="138" count="10" type="cond" truecount="1" falsecount="0"/> But it seems the coverage is wrong. jest tells me the |
b1f980f
to
2967fe4
Compare
packages/ownership-providers/src/__tests__/FullOwnershipProvider.test.ts
Outdated
Show resolved
Hide resolved
packages/ownership-providers/src/__tests__/FullOwnershipProvider.test.ts
Outdated
Show resolved
Hide resolved
if ('payers' in options && options.payers?.length === 0 && !options.autoInject) { | ||
errors.throwError('no payer is provided, but autoInject is `false`'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should check if the fee is paid to avoid repeating fee payment
if (inputCapacitys - outputsCapacity >= neededFee) {
return tx
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic of detecting if tx-fee is already paid: https://github.com/ckb-js/nexus/pull/127/files#diff-4212a8e65e25ac3827c0789664613414267d82d12237316f5b3adf09ac533476R209-R215
Is it better to run this logic before validating input parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think validating parameter first is better.
Thinking the user give a invalid parameter, but because of detecting tx fee already paid, it is not throw.
It is not Intuitive.
|
||
// feeFromTransactionSize - (sum(inputsCapacity) - sum(outputsCapacity)) | ||
let requireFee = calculateFeeCompatible(currentTransactionSize, feeRate).sub( | ||
sumCapacity(txSkeleton.get('inputs')).sub(sumCapacity(txSkeleton.get('outputs'))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// FIXME detect if it is a DAO unlock transaction first
} | ||
|
||
/** | ||
* Pay the transaction fee using the specified lock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// **NOT** support DAO unlock transaction yet, please consider using `lumos`'s `payFee`
@IronLu233 could you comment for the |
🚀 PR was released in |
injectCapacity
payFee
collector
signTransaction
update(2023-03-20):
{ckb: InjectedCkb}
to{ckb: InjectedCkb , rpcUrl: string }
since theScriptConfig
is required for theProvider
nexus/packages/extension-chrome/src/services/ownership/backend/backendUtils.ts
Lines 66 to 87 in abadb89
🐤 Download canary assets:
nexus--canary.127.4635976068.zip