Skip to content

Commit

Permalink
Merge pull request #221 from nervina-labs/develop
Browse files Browse the repository at this point in the history
Release v0.9.0
  • Loading branch information
duanyytop authored Mar 21, 2023
2 parents 2b74786 + 8f3e408 commit 79ad5fe
Show file tree
Hide file tree
Showing 29 changed files with 504 additions and 374 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,6 @@ dist
# TernJS port file
.tern-port

.vscode/

lib
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
. "$(dirname "$0")/_/husky.sh"

yarn lint
yarn format
yarn check
4 changes: 2 additions & 2 deletions example/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const run = async () => {
'0x490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80114000000dc70f33de86fdf381b4fc5bf092bb23d02774801',
page: 0,
pageSize: 3,
cotaId: "0xb066e0f068aa8be6548063a18d811c489a9e2141",
cotaId: '0xb066e0f068aa8be6548063a18d811c489a9e2141',
})
console.log(JSON.stringify(holdsWithCotaId))

Expand Down Expand Up @@ -63,7 +63,7 @@ const run = async () => {
const cotaCount = await aggregator.getCotaCount({
lockScript:
'0x490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80114000000dc70f33de86fdf381b4fc5bf092bb23d02774801',
cotaId: '0xb22585a8053af3fed0fd39127f5b1487ce08b756',
cotaId: '0xb22585a8053af3fed0fd39127f5b1487ce08b756',
})
console.log(JSON.stringify(cotaCount))
}
Expand Down
5 changes: 4 additions & 1 deletion example/aggregator/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const { Aggregator } = require('@nervina-labs/cota-sdk')

const run = async () => {
const aggregator = new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' })
const aggregator = new Aggregator({
registryUrl: 'http://localhost:3050',
cotaUrl: 'https://cota.nervina.dev/mainnet-aggregator',
})
const holds = await aggregator.getHoldCotaNft({
lockScript:
'0x490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80114000000dc70f33de86fdf381b4fc5bf092bb23d02774801',
Expand Down
8 changes: 4 additions & 4 deletions example/aggregator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"build": "tsc"
},
"dependencies": {
"@nervina-labs/cota-sdk": "0.7.1",
"@types/node": "18.11.9",
"@nervina-labs/cota-sdk": "0.8.0",
"@types/node": "18.11.13",
"ts-node": "10.9.1",
"tslib": "2.4.1",
"typescript": "4.8.3"
"typescript": "4.9.5"
}
}
}
50 changes: 28 additions & 22 deletions example/aggregator/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@nervina-labs/cota-sdk@0.7.1":
version "0.7.1"
resolved "https://registry.yarnpkg.com/@nervina-labs/cota-sdk/-/cota-sdk-0.7.1.tgz#a083a390ac514e56139a356701a368fe964f6e2e"
integrity sha512-EBnhifgro41OsSCBFF6s/f3cJP5CVv/aRv/9L3x5nm471ePZ2cHNMXNBIkjjlfximfmQnV29Mrt3kctV82EvjQ==
"@nervina-labs/cota-sdk@0.8.0":
version "0.8.0"
resolved "https://registry.yarnpkg.com/@nervina-labs/cota-sdk/-/cota-sdk-0.8.0.tgz#89028c2874e2bf1f226f3fc95bbc567bca8f34ac"
integrity sha512-3DwI26csftPtvnjFS8Cauf2ybu+8ESLVsGEUQn69aK5m3PKhXJqfuT2DpsXK2v4dmDEQ8MojgK2S0OooH/37ng==
dependencies:
"@nervosnetwork/ckb-sdk-core" "^0.103.0"
"@nervosnetwork/ckb-sdk-utils" "^0.103.0"
"@nervosnetwork/ckb-types" "^0.103.0"
axios "^0.27.2"
axios "^1.0.0"
camelcase-keys "^7.0.2"
convert-keys "1.3.4"

Expand Down Expand Up @@ -94,10 +94,10 @@
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e"
integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==

"@types/[email protected].9":
version "18.11.9"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.9.tgz#02d013de7058cea16d36168ef2fc653464cfbad4"
integrity sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==
"@types/[email protected].13":
version "18.11.13"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.13.tgz#dff34f226ec1ac0432ae3b136ec5552bd3b9c0fe"
integrity sha512-IASpMGVcWpUsx5xBOrxMj7Bl8lqfuTY7FKAnPmu5cHkfQVWF8GulWS1jbRqA934qZL35xh5xN/+Xe/i26Bod4w==

acorn-walk@^8.1.1:
version "8.2.0"
Expand Down Expand Up @@ -126,13 +126,14 @@ [email protected]:
dependencies:
follow-redirects "^1.14.0"

axios@^0.27.2:
version "0.27.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==
axios@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.2.0.tgz#1cb65bd75162c70e9f8d118a905126c4a201d383"
integrity sha512-zT7wZyNYu3N5Bu0wuZ6QccIf93Qk1eV8LOewxgjOZFd2DenOs98cJ7+Y6703d0wkaXGY6/nZd4EweJaHz9uzQw==
dependencies:
follow-redirects "^1.14.9"
follow-redirects "^1.15.0"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

[email protected]:
version "2.0.0"
Expand Down Expand Up @@ -214,10 +215,10 @@ follow-redirects@^1.14.0:
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==

follow-redirects@^1.14.9:
version "1.15.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.0.tgz#06441868281c86d0dda4ad8bdaead2d02dca89d4"
integrity sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ==
follow-redirects@^1.15.0:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==

form-data@^4.0.0:
version "4.0.0"
Expand Down Expand Up @@ -307,6 +308,11 @@ minimalistic-crypto-utils@^1.0.1:
resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a"
integrity sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=

proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

quick-lru@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-5.1.1.tgz#366493e6b3e42a3a6885e2e99d18f80fb7a8c932"
Expand Down Expand Up @@ -346,10 +352,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.8.3:
version "4.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.3.tgz#d59344522c4bc464a65a730ac695007fdb66dd88"
integrity sha512-goMHfm00nWPa8UvR/CPSvykqf6dVV8x/dp0c5mFTMTIu0u0FlGWRioyy7Nn0PGAdHxpJZnuO/ut+PpQ8UiHAig==
typescript@4.9.5:
version "4.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

v8-compile-cache-lib@^3.0.1:
version "3.0.1"
Expand Down
22 changes: 14 additions & 8 deletions example/claim-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ const RECEIVER_ADDRESS = 'ckt1qyqy6xew5q449zg5du7wdjhgrxschjkg3n2q8h5ycc'

const secp256k1CellDep = (isMainnet: boolean): CKBComponents.CellDep => {
if (isMainnet) {
return { outPoint: {
txHash: "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c",
index: "0x0",
}, depType: 'depGroup' }
return {
outPoint: {
txHash: '0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c',
index: '0x0',
},
depType: 'depGroup',
}
}
return {
outPoint: {
txHash: '0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37',
index: '0x0',
},
depType: 'depGroup',
}
return { outPoint: {
txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37",
index: "0x0",
}, depType: 'depGroup' }
}

const run = async () => {
Expand Down
22 changes: 14 additions & 8 deletions example/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ const RECEIVER_ADDRESS = 'ckt1qyqy6xew5q449zg5du7wdjhgrxschjkg3n2q8h5ycc'

const secp256k1CellDep = (isMainnet: boolean): CKBComponents.CellDep => {
if (isMainnet) {
return { outPoint: {
txHash: "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c",
index: "0x0",
}, depType: 'depGroup' }
return {
outPoint: {
txHash: '0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c',
index: '0x0',
},
depType: 'depGroup',
}
}
return {
outPoint: {
txHash: '0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37',
index: '0x0',
},
depType: 'depGroup',
}
return { outPoint: {
txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37",
index: "0x0",
}, depType: 'depGroup' }
}

const run = async () => {
Expand Down
28 changes: 17 additions & 11 deletions example/issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ const TEST_ADDRESS = 'ckt1qyq0scej4vn0uka238m63azcel7cmcme7f2sxj5ska'

const secp256k1CellDep = (isMainnet: boolean): CKBComponents.CellDep => {
if (isMainnet) {
return { outPoint: {
txHash: "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c",
index: "0x0",
}, depType: 'depGroup' }
return {
outPoint: {
txHash: '0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c',
index: '0x0',
},
depType: 'depGroup',
}
}
return {
outPoint: {
txHash: '0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37',
index: '0x0',
},
depType: 'depGroup',
}
return { outPoint: {
txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37",
index: "0x0",
}, depType: 'depGroup' }
}

const run = async () => {
Expand All @@ -32,9 +38,9 @@ const run = async () => {
const cotaLock = addressToScript(TEST_ADDRESS)

const issuer: IssuerInfo = {
name: "Nervina Labs",
description: "Melting Two Worlds Together.",
avatar: "https://i.loli.net/2021/04/29/IigbpOWP8fw9qDn.png",
name: 'Nervina Labs',
description: 'Melting Two Worlds Together.',
avatar: 'https://i.loli.net/2021/04/29/IigbpOWP8fw9qDn.png',
}

let rawTx = await generateIssuerInfoTx(service, cotaLock, issuer, FEE, isMainnet)
Expand Down
16 changes: 12 additions & 4 deletions example/mainnet/define.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ const run = async () => {
const isMainnet = true

const service = {
collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }),
aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }),
collector: new Collector({
ckbNodeUrl: 'https://mainnet.ckb.dev/rpc',
ckbIndexerUrl: 'https://mainnet.ckb.dev/indexer',
}),
aggregator: new Aggregator({
registryUrl: 'http://localhost:3050',
cotaUrl: 'https://cota.nervina.dev/mainnet-aggregator',
}),
}
const ckb = service.collector.getCkb()
const defineLock = addressToScript(TEST_ADDRESS)
Expand All @@ -48,10 +54,12 @@ const run = async () => {
console.log(`cotaId: ${cotaId}`)
rawTx.cellDeps.push(secp256k1CellDep(isMainnet))

console.log(JSON.stringify(rawTx))

const signedTx = ckb.signTransaction(TEST_PRIVATE_KEY)(rawTx)
console.log(JSON.stringify(signedTx))
let txHash = await ckb.rpc.sendTransaction(signedTx, 'passthrough')
console.info(`Define cota nft tx has been sent with tx hash ${txHash}`)
// let txHash = await ckb.rpc.sendTransaction(signedTx, 'passthrough')
// console.info(`Define cota nft tx has been sent with tx hash ${txHash}`)
}

run()
26 changes: 21 additions & 5 deletions example/mainnet/mint.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ const TEST_PRIVATE_KEY = '0x-example'
const TEST_ADDRESS = 'ckb1qyqxx0xdw7g67eu35nuj0f237eg8skpdctuqwx39xm'
const RECEIVER_ADDRESS = 'ckb1qyqxx0xdw7g67eu35nuj0f237eg8skpdctuqwx39xm'

const withdrawals = Array(100)
.fill(0)
.map(() => ({
state: '0x00',
characteristic: '0x0505050505050505050505050505050505050505',
toLockScript: serializeScript(addressToScript(RECEIVER_ADDRESS)),
}))

const secp256k1CellDep = isMainnet => {
if (isMainnet) {
return {
Expand All @@ -30,15 +38,21 @@ const run = async () => {
const isMainnet = true

const service = {
collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }),
aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }),
collector: new Collector({
ckbNodeUrl: 'https://mainnet.ckb.dev/rpc',
ckbIndexerUrl: 'https://mainnet.ckb.dev/indexer',
}),
aggregator: new Aggregator({
registryUrl: 'http://localhost:3050',
cotaUrl: 'https://cota.nervina.dev/mainnet-aggregator',
}),
}
const ckb = service.collector.getCkb()
const mintLock = addressToScript(TEST_ADDRESS)

// If any tokenIndex of MintCotaInfo is not set, the tokenIndex will be set automatically with issued count.
const mintCotaInfo = {
cotaId: '0xae223946058e5b148045d11483df60b36dc28a30',
cotaId: '0xc4a5cbf26b597acf3b35c74f61931c33aa16a55e',
withdrawals: [
{
// tokenIndex: '0x00000000',
Expand All @@ -58,10 +72,12 @@ const run = async () => {
let rawTx = await generateMintCotaTx(service, mintLock, mintCotaInfo, FEE, isMainnet)
rawTx.cellDeps.push(secp256k1CellDep(isMainnet))

console.log(JSON.stringify(rawTx))

const signedTx = ckb.signTransaction(TEST_PRIVATE_KEY)(rawTx)
console.log(JSON.stringify(signedTx))
let txHash = await ckb.rpc.sendTransaction(signedTx, 'passthrough')
console.info(`Mint cota nft tx has been sent with tx hash ${txHash}`)
// let txHash = await ckb.rpc.sendTransaction(signedTx, 'passthrough')
// console.info(`Mint cota nft tx has been sent with tx hash ${txHash}`)
}

run()
4 changes: 2 additions & 2 deletions example/mainnet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"description": "The examples for mainnet",
"license": "MIT",
"dependencies": {
"@nervina-labs/cota-sdk": "0.7.1"
"@nervina-labs/cota-sdk": "0.8.0"
}
}
}
18 changes: 13 additions & 5 deletions example/mainnet/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,20 @@ const run = async () => {
const isMainnet = true

const service = {
collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }),
aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }),
collector: new Collector({
ckbNodeUrl: 'https://mainnet.ckb.dev/rpc',
ckbIndexerUrl: 'https://mainnet.ckb.dev/indexer',
}),
aggregator: new Aggregator({
registryUrl: 'https://cota.nervina.dev/mainnet-registry-aggregator',
cotaUrl: 'https://cota.nervina.dev/mainnet-aggregator',
}),
}
const ckb = service.collector.getCkb()
const provideCKBLock = addressToScript(TEST_ADDRESS)
const unregisteredCotaLock = addressToScript(TEST_ADDRESS)
const unregisteredCotaLock = addressToScript(
'ckb1qzl58smqy32hnrq6vxjedcxe2fugvnz497h7yvwqvwel40uh4rltcqdjejyul32m2jmnu86w4esltzkg5k3ej3gpwhzrx',
)

let rawTx = await generateRegisterCotaTx(service, [unregisteredCotaLock], provideCKBLock, FEE, isMainnet)
rawTx.cellDeps.push(secp256k1CellDep(isMainnet))
Expand Down Expand Up @@ -68,8 +76,8 @@ const run = async () => {
witnesses: signedWitnesses.map(witness => (typeof witness === 'string' ? witness : serializeWitnessArgs(witness))),
}
console.log(JSON.stringify(signedTx))
let txHash = await ckb.rpc.sendTransaction(signedTx, 'passthrough')
console.log(`Register cota cell tx has been sent with tx hash ${txHash}`)
// let txHash = await ckb.rpc.sendTransaction(signedTx, 'passthrough')
// console.log(`Register cota cell tx has been sent with tx hash ${txHash}`)
}

run()
Loading

0 comments on commit 79ad5fe

Please sign in to comment.