Skip to content

Commit

Permalink
Merge pull request #198 from nervina-labs/develop
Browse files Browse the repository at this point in the history
Release v0.8.0
  • Loading branch information
duanyytop authored Dec 5, 2022
2 parents 89a25db + 4fb3742 commit 2b74786
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 153 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: actions/[email protected].0
- uses: actions/[email protected].1
with:
node-version: '14'
- name: Install dependency
Expand Down
6 changes: 3 additions & 3 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.6.6",
"@types/node": "17.0.21",
"@nervina-labs/cota-sdk": "0.7.1",
"@types/node": "18.11.9",
"ts-node": "10.9.1",
"tslib": "2.4.0",
"tslib": "2.4.1",
"typescript": "4.8.3"
}
}
24 changes: 12 additions & 12 deletions example/aggregator/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@nervina-labs/cota-sdk@0.6.6":
version "0.6.6"
resolved "https://registry.yarnpkg.com/@nervina-labs/cota-sdk/-/cota-sdk-0.6.6.tgz#cf9b164ec49472bed7dbfec1b0e52472f1d71149"
integrity sha512-H+UXxKx/H5qYbjT0osCgRrjOuSQyoXeeJkJw6IeIPx3F0P0kBR+CHuP8Hk6sC0Zan+NLvKRwnrWedBkcyTNOGw==
"@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==
dependencies:
"@nervosnetwork/ckb-sdk-core" "^0.103.0"
"@nervosnetwork/ckb-sdk-utils" "^0.103.0"
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/node@17.0.21":
version "17.0.21"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.21.tgz#864b987c0c68d07b4345845c3e63b75edd143644"
integrity sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==
"@types/node@18.11.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==

acorn-walk@^8.1.1:
version "8.2.0"
Expand Down Expand Up @@ -336,10 +336,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==

[email protected].0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3"
integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==
[email protected].1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.1.tgz#0d0bfbaac2880b91e22df0768e55be9753a5b17e"
integrity sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==

type-fest@^1.2.1:
version "1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion 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.6.6"
"@nervina-labs/cota-sdk": "0.7.1"
}
}
8 changes: 4 additions & 4 deletions example/mainnet/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@nervina-labs/cota-sdk@0.6.6":
version "0.6.6"
resolved "https://registry.yarnpkg.com/@nervina-labs/cota-sdk/-/cota-sdk-0.6.6.tgz#cf9b164ec49472bed7dbfec1b0e52472f1d71149"
integrity sha512-H+UXxKx/H5qYbjT0osCgRrjOuSQyoXeeJkJw6IeIPx3F0P0kBR+CHuP8Hk6sC0Zan+NLvKRwnrWedBkcyTNOGw==
"@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==
dependencies:
"@nervosnetwork/ckb-sdk-core" "^0.103.0"
"@nervosnetwork/ckb-sdk-utils" "^0.103.0"
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervina-labs/cota-sdk",
"version": "0.7.1",
"version": "0.8.0",
"description": "The SDK of CoTA",
"repository": "[email protected]:nervina-labs/cota-sdk-js.git",
"author": "duanyytop <[email protected]>",
Expand All @@ -27,23 +27,23 @@
"@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"
},
"devDependencies": {
"@types/crypto-js": "4.1.1",
"@types/node": "17.0.31",
"@typescript-eslint/parser": "5.38.1",
"@types/node": "18.11.9",
"@typescript-eslint/parser": "5.45.0",
"babel-eslint": "10.1.0",
"eslint": "8.24.0",
"eslint": "8.28.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-prettier": "4.2.1",
"husky": "8.0.1",
"prettier": "2.7.1",
"husky": "8.0.2",
"prettier": "2.8.0",
"ts-node": "10.9.1",
"tslib": "2.4.0",
"tslib": "2.4.1",
"typescript": "4.8.3"
},
"homepage": "https://github.com/nervina-labs/cota-sdk-js#readme"
Expand Down
2 changes: 1 addition & 1 deletion src/collector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class Collector {
headers: {
'Content-Type': 'application/json',
},
timeout: 20000,
timeout: 3000000,
data: body,
})
).data
Expand Down
2 changes: 1 addition & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const TestnetInfo = {
} as CKBComponents.Script,

CotaTypeDep: {
outPoint: { txHash: '0xd8c7396f955348bd74a8ed4398d896dad931977b7c1e3f117649765cd3d75b86', index: '0x0' },
outPoint: { txHash: '0x636a786001f87cb615acfcf408be0f9a1f077001f0bbc75ca54eadfe7e221713', index: '0x0' },
depType: 'depGroup',
} as CKBComponents.CellDep,

Expand Down
48 changes: 3 additions & 45 deletions src/service/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getAlwaysSuccessCellDep,
getCotaCellDep,
} from '../../constants'
import { append0x, remove0x, u64ToBe } from '../../utils/hex'
import { append0x, remove0x } from '../../utils/hex'

const COTA_CELL_CAPACITY = BigInt(150) * BigInt(100000000)

Expand Down Expand Up @@ -75,10 +75,10 @@ export const generateRegisterCotaTx = async (
outputs[length - 1].capacity = `0x${(BigInt(outputs[length - 1].capacity) - fee).toString(16)}`

const lockHashes = cotaLocks.map(lock => scriptToHash(lock))
const { smtRootHash, registrySmtEntry, outputAccountNum } = await service.aggregator.generateRegisterCotaSmt(
const { smtRootHash, registrySmtEntry } = await service.aggregator.generateRegisterCotaSmt(
lockHashes,
)
const registryCellData = `0x01${smtRootHash}${u64ToBe(BigInt(outputAccountNum))}`
const registryCellData = `0x02${smtRootHash}`

const outputsData = outputs.map((_, i) => (i === 0 ? registryCellData : i !== outputs.length - 1 ? '0x02' : '0x'))

Expand All @@ -98,45 +98,3 @@ export const generateRegisterCotaTx = async (
rawTx.witnesses = rawTx.inputs.map((_, i) => (i === 0 ? registryWitness : i === 1 ? emptyWitness : '0x'))
return rawTx
}

export const generateUpdateCcidsTx = async (
service: Service,
fee = FEE,
isMainnet = false,
): Promise<CKBComponents.RawTransactionToSign> => {
const registryLock = getAlwaysSuccessLock(isMainnet)
const registryType = getRegistryTypeScript(isMainnet)
const registryCells = await service.collector.getCells(registryLock, registryType)
if (!registryCells || registryCells.length === 0) {
throw new Error("Registry cell doesn't exist")
}
let registryCell = registryCells[0]
let inputs = [
{
previousOutput: registryCell.outPoint,
since: '0x0',
},
]

let outputs = [registryCell.output]
outputs[0].capacity = `0x${(BigInt(outputs[0].capacity) - fee).toString(16)}`

const { smtRootHash, registrySmtEntry, outputAccountNum } = await service.aggregator.generateUpdateCcidsSmt()
const registryCellData = `0x01${smtRootHash}${u64ToBe(BigInt(outputAccountNum))}`

const outputsData = [registryCellData]

const cellDeps = [getAlwaysSuccessCellDep(isMainnet), getCotaCellDep(isMainnet)]
const registryWitness = serializeWitnessArgs({ lock: '', inputType: append0x(registrySmtEntry), outputType: '' })

let rawTx = {
version: '0x0',
cellDeps,
headerDeps: [],
inputs,
outputs,
outputsData,
witnesses: [registryWitness],
}
return rawTx
}
1 change: 0 additions & 1 deletion src/types/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export interface SmtResp {}
export interface RegistryResp {
smtRootHash: Byte32
registrySmtEntry: Bytes
outputAccountNum: bigint
blockNumber: bigint
}

Expand Down
Loading

0 comments on commit 2b74786

Please sign in to comment.