-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add typeHash and daoData when sync
- Loading branch information
1 parent
5efe225
commit 1b6b062
Showing
9 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import NodeService from 'services/node' | ||
import { ScriptHashType } from 'types/cell-types' | ||
import Core from '@nervosnetwork/ckb-sdk-core' | ||
import { SystemScript } from './lock-utils' | ||
import { scriptToHash } from '@nervosnetwork/ckb-sdk-utils' | ||
|
||
export default class DaoUtils { | ||
daoScript: SystemScript | ||
|
||
constructor(daoScript: SystemScript) { | ||
this.daoScript = daoScript | ||
} | ||
|
||
static daoScriptInfo: SystemScript | undefined | ||
|
||
static previousURL: string | undefined | ||
|
||
static async loadDaoScript(nodeURL: string): Promise<SystemScript> { | ||
const core = new Core(nodeURL) | ||
|
||
const genesisBlock = await core.rpc.getBlockByNumber(BigInt(0)) | ||
const systemCellTransaction = genesisBlock.transactions[0] | ||
const daoOutPoint = { | ||
txHash: systemCellTransaction.hash, | ||
index: '2' | ||
} | ||
|
||
const daoTypeHash = scriptToHash(systemCellTransaction.outputs[2].type!) | ||
|
||
return { | ||
codeHash: daoTypeHash, | ||
outPoint: daoOutPoint, | ||
hashType: ScriptHashType.Type | ||
} | ||
} | ||
|
||
static async daoScript(nodeURL: string = NodeService.getInstance().core.rpc.node.url): Promise<SystemScript> { | ||
if (DaoUtils.daoScriptInfo && nodeURL === DaoUtils.previousURL) { | ||
return DaoUtils.daoScriptInfo | ||
} | ||
|
||
DaoUtils.daoScriptInfo = await DaoUtils.loadDaoScript(nodeURL) | ||
DaoUtils.previousURL = nodeURL | ||
|
||
return DaoUtils.daoScriptInfo | ||
} | ||
|
||
static setDaoScript(info: SystemScript) { | ||
DaoUtils.daoScriptInfo = info | ||
DaoUtils.previousURL = NodeService.getInstance().core.rpc.node.url | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters