From 702016b34ab7dabb0b1eca1c56bbab6e5faf5f83 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 28 Feb 2022 21:38:27 +0000 Subject: [PATCH 1/7] chore(deps): update dependency @typescript-eslint/parser to v5.13.0 --- package.json | 2 +- yarn.lock | 58 ++++++++++++++++++++++++++-------------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 4a4d0a0..d7bf4a3 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "devDependencies": { "@types/crypto-js": "4.1.1", "@types/node": "17.0.21", - "@typescript-eslint/parser": "5.12.1", + "@typescript-eslint/parser": "5.13.0", "babel-eslint": "10.1.0", "convert-keys": "1.3.4", "eslint": "8.10.0", diff --git a/yarn.lock b/yarn.lock index 4dc4937..2ea89c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -239,48 +239,48 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.21.tgz#864b987c0c68d07b4345845c3e63b75edd143644" integrity sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ== -"@typescript-eslint/parser@5.12.1": - version "5.12.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.12.1.tgz#b090289b553b8aa0899740d799d0f96e6f49771b" - integrity sha512-6LuVUbe7oSdHxUWoX/m40Ni8gsZMKCi31rlawBHt7VtW15iHzjbpj2WLiToG2758KjtCCiLRKZqfrOdl3cNKuw== - dependencies: - "@typescript-eslint/scope-manager" "5.12.1" - "@typescript-eslint/types" "5.12.1" - "@typescript-eslint/typescript-estree" "5.12.1" +"@typescript-eslint/parser@5.13.0": + version "5.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.13.0.tgz#0394ed8f2f849273c0bf4b811994d177112ced5c" + integrity sha512-GdrU4GvBE29tm2RqWOM0P5QfCtgCyN4hXICj/X9ibKED16136l9ZpoJvCL5pSKtmJzA+NRDzQ312wWMejCVVfg== + dependencies: + "@typescript-eslint/scope-manager" "5.13.0" + "@typescript-eslint/types" "5.13.0" + "@typescript-eslint/typescript-estree" "5.13.0" debug "^4.3.2" -"@typescript-eslint/scope-manager@5.12.1": - version "5.12.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.12.1.tgz#58734fd45d2d1dec49641aacc075fba5f0968817" - integrity sha512-J0Wrh5xS6XNkd4TkOosxdpObzlYfXjAFIm9QxYLCPOcHVv1FyyFCPom66uIh8uBr0sZCrtS+n19tzufhwab8ZQ== +"@typescript-eslint/scope-manager@5.13.0": + version "5.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.13.0.tgz#cf6aff61ca497cb19f0397eea8444a58f46156b6" + integrity sha512-T4N8UvKYDSfVYdmJq7g2IPJYCRzwtp74KyDZytkR4OL3NRupvswvmJQJ4CX5tDSurW2cvCc1Ia1qM7d0jpa7IA== dependencies: - "@typescript-eslint/types" "5.12.1" - "@typescript-eslint/visitor-keys" "5.12.1" + "@typescript-eslint/types" "5.13.0" + "@typescript-eslint/visitor-keys" "5.13.0" -"@typescript-eslint/types@5.12.1": - version "5.12.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.12.1.tgz#46a36a28ff4d946821b58fe5a73c81dc2e12aa89" - integrity sha512-hfcbq4qVOHV1YRdhkDldhV9NpmmAu2vp6wuFODL71Y0Ixak+FLeEU4rnPxgmZMnGreGEghlEucs9UZn5KOfHJA== +"@typescript-eslint/types@5.13.0": + version "5.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.13.0.tgz#da1de4ae905b1b9ff682cab0bed6b2e3be9c04e5" + integrity sha512-LmE/KO6DUy0nFY/OoQU0XelnmDt+V8lPQhh8MOVa7Y5k2gGRd6U9Kp3wAjhB4OHg57tUO0nOnwYQhRRyEAyOyg== -"@typescript-eslint/typescript-estree@5.12.1": - version "5.12.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.12.1.tgz#6a9425b9c305bcbc38e2d1d9a24c08e15e02b722" - integrity sha512-ahOdkIY9Mgbza7L9sIi205Pe1inCkZWAHE1TV1bpxlU4RZNPtXaDZfiiFWcL9jdxvW1hDYZJXrFm+vlMkXRbBw== +"@typescript-eslint/typescript-estree@5.13.0": + version "5.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.13.0.tgz#b37c07b748ff030a3e93d87c842714e020b78141" + integrity sha512-Q9cQow0DeLjnp5DuEDjLZ6JIkwGx3oYZe+BfcNuw/POhtpcxMTy18Icl6BJqTSd+3ftsrfuVb7mNHRZf7xiaNA== dependencies: - "@typescript-eslint/types" "5.12.1" - "@typescript-eslint/visitor-keys" "5.12.1" + "@typescript-eslint/types" "5.13.0" + "@typescript-eslint/visitor-keys" "5.13.0" debug "^4.3.2" globby "^11.0.4" is-glob "^4.0.3" semver "^7.3.5" tsutils "^3.21.0" -"@typescript-eslint/visitor-keys@5.12.1": - version "5.12.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.12.1.tgz#f722da106c8f9695ae5640574225e45af3e52ec3" - integrity sha512-l1KSLfupuwrXx6wc0AuOmC7Ko5g14ZOQ86wJJqRbdLbXLK02pK/DPiDDqCc7BqqiiA04/eAA6ayL0bgOrAkH7A== +"@typescript-eslint/visitor-keys@5.13.0": + version "5.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.13.0.tgz#f45ff55bcce16403b221ac9240fbeeae4764f0fd" + integrity sha512-HLKEAS/qA1V7d9EzcpLFykTePmOQqOFim8oCvhY3pZgQ8Hi38hYpHd9e5GN6nQBFQNecNhws5wkS9Y5XIO0s/g== dependencies: - "@typescript-eslint/types" "5.12.1" + "@typescript-eslint/types" "5.13.0" eslint-visitor-keys "^3.0.0" acorn-jsx@^5.3.1: From 9e5f696c556f38d3a5dce307bcb224adb4948b16 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 1 Mar 2022 01:40:37 +0000 Subject: [PATCH 2/7] chore(deps): update dependency typescript to v4.6.2 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d7bf4a3..6ac09bc 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "prettier": "2.5.1", "ts-node": "10.5.0", "tslib": "2.3.1", - "typescript": "4.5.5" + "typescript": "4.6.2" }, "homepage": "https://github.com/nervina-labs/cota-sdk-js#readme" } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 2ea89c6..5ccd57f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1657,10 +1657,10 @@ type-fest@^1.2.1: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-1.4.0.tgz#e9fb813fe3bf1744ec359d55d1affefa76f14be1" integrity sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA== -typescript@4.5.5: - version "4.5.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3" - integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA== +typescript@4.6.2: + version "4.6.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.2.tgz#fe12d2727b708f4eef40f51598b3398baa9611d4" + integrity sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg== unbox-primitive@^1.0.1: version "1.0.1" From 2982dad8beb1cd067b035dcf5302c5e301e37fab Mon Sep 17 00:00:00 2001 From: duanyytop Date: Tue, 1 Mar 2022 10:25:25 +0800 Subject: [PATCH 3/7] feat: Support claim_update --- src/aggregator/index.ts | 12 +++++++ src/service/cota/claim_update.ts | 62 ++++++++++++++++++++++++++++++++ src/types/request.ts | 21 +++++++++++ src/types/response.ts | 12 +++++++ 4 files changed, 107 insertions(+) create mode 100644 src/service/cota/claim_update.ts diff --git a/src/aggregator/index.ts b/src/aggregator/index.ts index 89a14a9..788c193 100644 --- a/src/aggregator/index.ts +++ b/src/aggregator/index.ts @@ -11,6 +11,8 @@ import { UpdateReq, WithdrawalReq, GetCotaSenderReq, + ClaimUpdateReq, + TransferUpdateReq, } from '../types/request' import { ClaimResp, @@ -26,6 +28,8 @@ import { UpdateResp, WithdrawalResp, GetCotaSenderResp, + ClaimUpdateResp, + TransferUpdateResp, } from '../types/response' import { Byte32 } from '../types/common' @@ -93,6 +97,14 @@ export class Aggregator { return (await this.baseRPC('generate_claim_cota_smt', claim)) as Promise } + async generateTransferUpdateCotaSmt(transfer: TransferUpdateReq): Promise { + return (await this.baseRPC('generate_transfer_update_cota_smt', transfer)) as Promise + } + + async generateClaimUpdateCotaSmt(claim: ClaimUpdateReq): Promise { + return (await this.baseRPC('generate_claim_update_cota_smt', claim)) as Promise + } + async generateUpdateCotaSmt(update: UpdateReq): Promise { return (await this.baseRPC('generate_update_cota_smt', update)) as Promise } diff --git a/src/service/cota/claim_update.ts b/src/service/cota/claim_update.ts new file mode 100644 index 0000000..d2b3ef3 --- /dev/null +++ b/src/service/cota/claim_update.ts @@ -0,0 +1,62 @@ +import { scriptToHash, serializeScript } from '@nervosnetwork/ckb-sdk-utils' +import { Service, CotaNft, ClaimUpdateReq } from '../..' +import { FEE, getCotaTypeScript, getCotaCellDep } from '../../constants' + +export const generateClaimUpdateCotaTx = async ( + service: Service, + cotaLock: CKBComponents.Script, + withdrawalLock: CKBComponents.Script, + nfts: CotaNft[], + fee = FEE, + isMainnet = false, +) => { + const cotaType = getCotaTypeScript(isMainnet) + const cotaCells = await service.collector.getCells(cotaLock, cotaType) + if (!cotaCells || cotaCells.length === 0) { + throw new Error("Cota cell doesn't exist") + } + const cotaCell = cotaCells[0] + + const inputs = [ + { + previousOutput: cotaCell.outPoint, + since: '0x0', + }, + ] + + const outputs = [cotaCell.output] + outputs[0].capacity = `0x${(BigInt(outputs[0].capacity) - fee).toString(16)}` + + const withdrawalLockHash = scriptToHash(withdrawalLock) + const withdrawalCotaCells = await service.collector.getCells(withdrawalLock, cotaType) + if (!withdrawalCotaCells || withdrawalCotaCells.length === 0) { + throw new Error("Withdrawal cota cell doesn't exist") + } + const withdrawalCotaCell = withdrawalCotaCells[0] + + const claimUpdateReq: ClaimUpdateReq = { + lockScript: serializeScript(cotaLock), + withdrawalLockHash, + nfts, + } + + const { smtRootHash, claimUpdateSmtEntry } = await service.aggregator.generateClaimUpdateCotaSmt(claimUpdateReq) + const outputsData = [`0x00${smtRootHash}`] + + const withdrawalCellDep: CKBComponents.CellDep = { outPoint: withdrawalCotaCell.outPoint, depType: 'code' } + const cellDeps = [withdrawalCellDep, getCotaCellDep(isMainnet)] + + const rawTx = { + version: '0x0', + cellDeps, + headerDeps: [], + inputs, + outputs, + outputsData, + witnesses: [], + } + rawTx.witnesses = rawTx.inputs.map((_, i) => + i > 0 ? '0x' : { lock: '', inputType: `0x07${claimUpdateSmtEntry}`, outputType: '' }, + ) + return rawTx +} diff --git a/src/types/request.ts b/src/types/request.ts index 41e7f5e..26c7ef6 100644 --- a/src/types/request.ts +++ b/src/types/request.ts @@ -66,6 +66,27 @@ export interface UpdateReq extends SmtReq { nfts: CotaNft[] } +export interface ClaimUpdateReq extends SmtReq { + lockScript: Bytes + withdrawalLockHash: Byte32 + nfts: CotaNft[] +} + +export interface TransferUpdate { + cotaId: Byte20 + tokenIndex: Byte4 + toLockScript: Bytes + state: Byte + characteristic: Byte20 +} + +export interface TransferUpdateReq extends SmtReq { + lockScript: Bytes + withdrawalLockHash: CKBComponents.Hash + transferOutPoint: Byte24 + transfers: TransferUpdate[] +} + export interface GetCotaReq extends SmtReq { lockScript: Bytes page: number diff --git a/src/types/response.ts b/src/types/response.ts index bbd40d2..7fbc5a0 100644 --- a/src/types/response.ts +++ b/src/types/response.ts @@ -44,6 +44,18 @@ export interface UpdateResp extends SmtResp { blockNumber: bigint } +export interface ClaimUpdateResp extends SmtResp { + smtRootHash: Byte32 + claimUpdateSmtEntry: Bytes + blockNumber: bigint +} + +export interface TransferUpdateResp extends SmtResp { + smtRootHash: Byte32 + transferUpdateSmtEntry: Bytes + blockNumber: bigint +} + export interface GetHoldResp extends SmtResp { total: number pageSize: number From 097152f6fcfd316555dfc5fffa0da27b35c077c6 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Tue, 1 Mar 2022 10:33:40 +0800 Subject: [PATCH 4/7] feat: Support transfer_update --- .../cota/{claim_update.ts => claim-update.ts} | 0 src/service/cota/index.ts | 2 + src/service/cota/transfer-update.ts | 61 +++++++++++++++++++ 3 files changed, 63 insertions(+) rename src/service/cota/{claim_update.ts => claim-update.ts} (100%) create mode 100644 src/service/cota/transfer-update.ts diff --git a/src/service/cota/claim_update.ts b/src/service/cota/claim-update.ts similarity index 100% rename from src/service/cota/claim_update.ts rename to src/service/cota/claim-update.ts diff --git a/src/service/cota/index.ts b/src/service/cota/index.ts index c28881b..16ecb28 100644 --- a/src/service/cota/index.ts +++ b/src/service/cota/index.ts @@ -4,3 +4,5 @@ export * from './withdraw' export * from './claim' export * from './update' export * from './transfer' +export * from './claim-update' +export * from './transfer-update' diff --git a/src/service/cota/transfer-update.ts b/src/service/cota/transfer-update.ts new file mode 100644 index 0000000..2e0808c --- /dev/null +++ b/src/service/cota/transfer-update.ts @@ -0,0 +1,61 @@ +import { scriptToHash, serializeOutPoint, serializeScript } from '@nervosnetwork/ckb-sdk-utils' +import { Service, TransferUpdate, TransferUpdateReq } from '../..' +import { FEE, getCotaTypeScript, getCotaCellDep } from '../../constants' +import { append0x } from '../../utils/hex' + +export const generateTransferUpdateCotaTx = async ( + service: Service, + cotaLock: CKBComponents.Script, + withdrawalLock: CKBComponents.Script, + transfers: TransferUpdate[], + fee = FEE, + isMainnet = false, +) => { + const cotaType = getCotaTypeScript(isMainnet) + const cotaCells = await service.collector.getCells(cotaLock, cotaType) + if (!cotaCells || cotaCells.length === 0) { + throw new Error("Cota cell doesn't exist") + } + const cotaCell = cotaCells[0] + const inputs = [ + { + previousOutput: cotaCell.outPoint, + since: '0x0', + }, + ] + const outputs = [cotaCell.output] + outputs[0].capacity = `0x${(BigInt(outputs[0].capacity) - fee).toString(16)}` + + const cotaLockScript = serializeScript(cotaLock) + const withdrawalLockHash = scriptToHash(withdrawalLock) + const withdrawalCotaCells = await service.collector.getCells(withdrawalLock, cotaType) + if (!withdrawalCotaCells || withdrawalCotaCells.length === 0) { + throw new Error("Withdrawal cota cell doesn't exist") + } + const withdrawalCotaCell = withdrawalCotaCells[0] + + const transferUpdateReq: TransferUpdateReq = { + lockScript: cotaLockScript, + withdrawalLockHash, + transferOutPoint: append0x(serializeOutPoint(cotaCell.outPoint).slice(26)), + transfers, + } + const { smtRootHash, transferUpdateSmtEntry } = await service.aggregator.generateTransferUpdateCotaSmt(transferUpdateReq) + const outputsData = [`0x00${smtRootHash}`] + + const withdrawalCellDep: CKBComponents.CellDep = { outPoint: withdrawalCotaCell.outPoint, depType: 'code' } + const cellDeps = [withdrawalCellDep, getCotaCellDep(isMainnet)] + const rawTx = { + version: '0x0', + cellDeps, + headerDeps: [], + inputs, + outputs, + outputsData, + witnesses: [], + } + rawTx.witnesses = rawTx.inputs.map((_, i) => + i > 0 ? '0x' : { lock: '', inputType: `0x08${transferUpdateSmtEntry}`, outputType: '' }, + ) + return rawTx +} From 2ecb9cb26c415b299821cfc46c4e196b20f03efe Mon Sep 17 00:00:00 2001 From: duanyytop Date: Tue, 1 Mar 2022 11:00:14 +0800 Subject: [PATCH 5/7] feat: Add claim_update and transfer_update --- example/claim-update.ts | 45 ++++++++++++++++++++++++++++++++++++ example/mint.ts | 6 ++--- example/transfer-update.ts | 47 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 example/claim-update.ts create mode 100644 example/transfer-update.ts diff --git a/example/claim-update.ts b/example/claim-update.ts new file mode 100644 index 0000000..bbd6383 --- /dev/null +++ b/example/claim-update.ts @@ -0,0 +1,45 @@ +import { addressToScript } from '@nervosnetwork/ckb-sdk-utils' +import { Collector } from '../src/collector' +import { Aggregator } from '../src/aggregator' +import { generateClaimUpdateCotaTx } from '../src/service/cota' +import { CotaNft, Service } from '../src' +import CKB from '@nervosnetwork/ckb-sdk-core' + +const TEST_ADDRESS = 'ckt1qyq0scej4vn0uka238m63azcel7cmcme7f2sxj5ska' +const RECEIVER_PRIVATE_KEY = '0xcf56c11ce3fbec627e5118acd215838d1f9c5048039792d42143f933cde76311' +const RECEIVER_ADDRESS = 'ckt1qyqdcu8n8h5xlhecrd8ut0cf9wer6qnhfqqsnz3lw9' + +const secp256k1CellDep = async (ckb: CKB): Promise => { + const secp256k1Dep = (await ckb.loadDeps()).secp256k1Dep + return { outPoint: secp256k1Dep.outPoint, depType: 'depGroup' } +} + +const run = async () => { + const service: Service = { + collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), + aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), + } + const ckb = service.collector.getCkb() + const claimLock = addressToScript(RECEIVER_ADDRESS) + const withdrawLock = addressToScript(TEST_ADDRESS) + + const nfts: CotaNft[] = [ + { + cotaId: '0x678319cdf1f343aa4adf379bafebbb2fc9360ac9', + tokenIndex: '0x00000000', + state: '0x00', + characteristic: '0xa5a5a50505050505050505050505050505050505', + }, + ] + let rawTx = await generateClaimUpdateCotaTx(service, claimLock, withdrawLock, nfts) + + const secp256k1Dep = await secp256k1CellDep(ckb) + rawTx.cellDeps.push(secp256k1Dep) + + const signedTx = ckb.signTransaction(RECEIVER_PRIVATE_KEY)(rawTx) + console.log(JSON.stringify(signedTx)) + let txHash = await ckb.rpc.sendTransaction(signedTx, 'passthrough') + console.info(`Claim and update cota nft tx has been sent with tx hash ${txHash}`) +} + +run() diff --git a/example/mint.ts b/example/mint.ts index 0365f5b..c3a2be6 100644 --- a/example/mint.ts +++ b/example/mint.ts @@ -23,18 +23,18 @@ const run = async () => { const mintLock = addressToScript(TEST_ADDRESS) const mintCotaInfo: MintCotaInfo = { - cotaId: '0x1deb31f603652bf59ff5027b522e1d81c288b72f', + cotaId: '0x678319cdf1f343aa4adf379bafebbb2fc9360ac9', withdrawals: [ { tokenIndex: '0x00000000', state: '0x00', - characteristic: '0xa505050505050505050505050505050505050505', + characteristic: '0x0505050505050505050505050505050505050505', toLockScript: serializeScript(addressToScript(RECEIVER_ADDRESS)), }, { tokenIndex: '0x00000001', state: '0x00', - characteristic: '0xa505050505050505050505050505050505050505', + characteristic: '0x0505050505050505050505050505050505050505', toLockScript: serializeScript(addressToScript(RECEIVER_ADDRESS)), }, ], diff --git a/example/transfer-update.ts b/example/transfer-update.ts new file mode 100644 index 0000000..ae5dd25 --- /dev/null +++ b/example/transfer-update.ts @@ -0,0 +1,47 @@ +import { addressToScript, serializeScript } from '@nervosnetwork/ckb-sdk-utils' +import { Collector } from '../src/collector' +import { Aggregator } from '../src/aggregator' +import { generateTransferUpdateCotaTx } from '../src/service/cota' +import { Service, TransferUpdate } from '../src' +import CKB from '@nervosnetwork/ckb-sdk-core' + +const TEST_ADDRESS = 'ckt1qyq0scej4vn0uka238m63azcel7cmcme7f2sxj5ska' +const RECEIVER_PRIVATE_KEY = '0xcf56c11ce3fbec627e5118acd215838d1f9c5048039792d42143f933cde76311' +const RECEIVER_ADDRESS = 'ckt1qyqdcu8n8h5xlhecrd8ut0cf9wer6qnhfqqsnz3lw9' +const OTHER_ADDRESS = 'ckt1qyqz8vxeyrv4nur4j27ktp34fmwnua9wuyqqggd748' + +const secp256k1CellDep = async (ckb: CKB): Promise => { + const secp256k1Dep = (await ckb.loadDeps()).secp256k1Dep + return { outPoint: secp256k1Dep.outPoint, depType: 'depGroup' } +} + +const run = async () => { + const service: Service = { + collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), + aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), + } + const ckb = service.collector.getCkb() + const cotaLock = addressToScript(RECEIVER_ADDRESS) + const withdrawLock = addressToScript(TEST_ADDRESS) + + const transfers: TransferUpdate[] = [ + { + cotaId: '0x678319cdf1f343aa4adf379bafebbb2fc9360ac9', + tokenIndex: '0x00000001', + toLockScript: serializeScript(addressToScript(OTHER_ADDRESS)), + state: '0x00', + characteristic: '0x2525250505050505050505050505050505050505', + }, + ] + let rawTx = await generateTransferUpdateCotaTx(service, cotaLock, withdrawLock, transfers) + + const secp256k1Dep = await secp256k1CellDep(ckb) + rawTx.cellDeps.push(secp256k1Dep) + + const signedTx = ckb.signTransaction(RECEIVER_PRIVATE_KEY)(rawTx) + console.log(JSON.stringify(signedTx)) + let txHash = await ckb.rpc.sendTransaction(signedTx, 'passthrough') + console.info(`Transfer and update cota nft tx has been sent with tx hash ${txHash}`) +} + +run() From 6717154db2a4e60c5c43dd0ae018e5a872bcd6c5 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Tue, 1 Mar 2022 11:02:03 +0800 Subject: [PATCH 6/7] chore: Bump version to v0.1.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6ac09bc..3a8e099 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nervina-labs/cota-sdk", - "version": "0.1.2", + "version": "0.1.3", "description": "The SDK of CoTA", "repository": "git@github.com:nervina-labs/cota-sdk-js.git", "author": "duanyytop ", From a5df2dc592a261404698287bf07dbf1765b14898 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Tue, 1 Mar 2022 11:05:57 +0800 Subject: [PATCH 7/7] docs: Update readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index eefe468..4a167d8 100644 --- a/README.md +++ b/README.md @@ -44,3 +44,5 @@ https://testnet.ckbapp.dev/indexer ---> ckb testnet indexer_rpc - [withdraw example](https://github.com/nervina-labs/cota-sdk-js/blob/develop/example/withdraw.ts): Generate withdrawing CoTA NFT transaction - [transfer example](https://github.com/nervina-labs/cota-sdk-js/blob/develop/example/transfer.ts): Generate transferring CoTA NFT transaction - [update example](https://github.com/nervina-labs/cota-sdk-js/blob/develop/example/update.ts): Generate updating CoTA NFT information transaction +- [claim&update example](https://github.com/nervina-labs/cota-sdk-js/blob/develop/example/claim-update.ts): Generate claiming and updateing CoTA NFT transaction +- [transfer&update example](https://github.com/nervina-labs/cota-sdk-js/blob/develop/example/transfer-update.ts): Generate transferring and updating CoTA NFT transaction