Skip to content

Commit

Permalink
Merge pull request #196 from nervina-labs/remove-ccid
Browse files Browse the repository at this point in the history
Remove registry ccid
  • Loading branch information
duanyytop authored Dec 5, 2022
2 parents 01374d3 + 420d3c7 commit 4fb3742
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 48 deletions.
2 changes: 1 addition & 1 deletion 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 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

0 comments on commit 4fb3742

Please sign in to comment.