@acala-network/chopsticks-core
@acala-network/chopsticks-core / Blockchain
Class: Blockchain
Defined in: packages/core/src/blockchain/index.ts:83
Local blockchain which provides access to blocks, txpool and methods to manipulate the chain such as build blocks, submit extrinsics, xcm and more!
Example
const chain = new Blockchain({
api,
buildBlockMode: BuildBlockMode.Manual,
inherentProviders,
header: {
hash: blockHash,
number: Number(header.number),
},
mockSignatureHost: true,
allowUnresolvedImports: true,
registeredTypes: {},
})
// build a block
chain.newBlock()
Constructors
new Blockchain()
new Blockchain(
options
):Blockchain
Defined in: packages/core/src/blockchain/index.ts:135
Parameters
options
Options for instantiating the blockchain
Returns
Properties
allowUnresolvedImports
readonly
allowUnresolvedImports:boolean
Defined in: packages/core/src/blockchain/index.ts:91
Allow wasm unresolved imports.
api
readonly
api:Api
Defined in: packages/core/src/blockchain/index.ts:85
API instance, for getting on-chain data.
db
readonly
db:undefined
|Database
Defined in: packages/core/src/blockchain/index.ts:87
Datasource for caching storage and blocks data.
headState
readonly
headState:HeadState
Defined in: packages/core/src/blockchain/index.ts:105
For subscribing and managing the head state.
mockSignatureHost
readonly
mockSignatureHost:boolean
Defined in: packages/core/src/blockchain/index.ts:89
Enable mock signature. Any signature starts with 0xdeadbeef and filled by 0xcd is considered valid
offchainWorker
readonly
offchainWorker:undefined
|OffchainWorker
Defined in: packages/core/src/blockchain/index.ts:107
processQueuedMessages
readonly
processQueuedMessages:boolean
=true
Defined in: packages/core/src/blockchain/index.ts:109
registeredTypes
readonly
registeredTypes:RegisteredTypes
Defined in: packages/core/src/blockchain/index.ts:94
Polkadot.js custom types registration.
Accessors
head
Get Signature
get head():
Block
Defined in: packages/core/src/blockchain/index.ts:184
Returns
runtimeLogLevel
Get Signature
get runtimeLogLevel():
number
Defined in: packages/core/src/blockchain/index.ts:192
Returns
number
Set Signature
set runtimeLogLevel(
level
):void
Defined in: packages/core/src/blockchain/index.ts:196
Parameters
level
number
Returns
void
txPool
Get Signature
get txPool():
TxPool
Defined in: packages/core/src/blockchain/index.ts:188
Returns
Methods
blocksInMemory()
blocksInMemory():
Block
[]
Defined in: packages/core/src/blockchain/index.ts:317
Get all blocks in memory.
Returns
Block
[]
buildRegistry()
buildRegistry(
metadata
,version
):Promise
<TypeRegistry
>
Defined in: packages/core/src/blockchain/index.ts:201
Parameters
metadata
`0x${string}`
version
Returns
Promise
<TypeRegistry
>
close()
close():
Promise
<void
>
Defined in: packages/core/src/blockchain/index.ts:545
Close the db and disconnect api.
Returns
Promise
<void
>
dryRunDmp()
dryRunDmp(
dmp
,at
?):Promise
<[`0x${string}`
,null
|`0x${string}`
][]>
Defined in: packages/core/src/blockchain/index.ts:479
Dry run dmp messages in block at
. Return the storage diff.
Parameters
dmp
at?
`0x${string}`
Returns
Promise
<[`0x${string}`
, null
| `0x${string}`
][]>
dryRunExtrinsic()
dryRunExtrinsic(
extrinsic
,at
?):Promise
<{outcome
:ApplyExtrinsicResult
;storageDiff
: [`0x${string}`
,null
|`0x${string}`
][]; }>
Defined in: packages/core/src/blockchain/index.ts:432
Dry run extrinsic in block at
.
Parameters
extrinsic
`0x${string}`
| { address
: string
; call
: `0x${string}`
; }
at?
`0x${string}`
Returns
Promise
<{ outcome
: ApplyExtrinsicResult
; storageDiff
: [`0x${string}`
, null
| `0x${string}`
][]; }>
dryRunHrmp()
dryRunHrmp(
hrmp
,at
?):Promise
<[`0x${string}`
,null
|`0x${string}`
][]>
Defined in: packages/core/src/blockchain/index.ts:457
Dry run hrmp messages in block at
. Return the storage diff.
Parameters
hrmp
Record
<number
, HorizontalMessage
[]>
at?
`0x${string}`
Returns
Promise
<[`0x${string}`
, null
| `0x${string}`
][]>
dryRunUmp()
dryRunUmp(
ump
,at
?):Promise
<[`0x${string}`
,null
|`0x${string}`
][]>
Defined in: packages/core/src/blockchain/index.ts:498
Dry run ump messages in block at
. Return the storage diff.
Parameters
ump
Record
<number
, `0x${string}`
[]>
at?
`0x${string}`
Returns
Promise
<[`0x${string}`
, null
| `0x${string}`
][]>
getBlock()
getBlock(
hash
?):Promise
<undefined
|Block
>
Defined in: packages/core/src/blockchain/index.ts:281
Get block by hash.
Parameters
hash?
`0x${string}`
Returns
Promise
<undefined
| Block
>
getBlockAt()
getBlockAt(
number
?):Promise
<undefined
|Block
>
Defined in: packages/core/src/blockchain/index.ts:256
Get block by number.
Parameters
number?
null
| number
Returns
Promise
<undefined
| Block
>
getInherents()
getInherents():
InherentProvider
[]
Defined in: packages/core/src/blockchain/index.ts:538
Get inherents of head.
Returns
loadBlockFromDB()
loadBlockFromDB(
hashOrNumber
):Promise
<undefined
|Block
>
Defined in: packages/core/src/blockchain/index.ts:225
Try to load block from db and register it. If pass in number, get block by number, else get block by hash.
Parameters
hashOrNumber
number
| `0x${string}`
Returns
Promise
<undefined
| Block
>
newBlock()
newBlock(
params
?):Promise
<Block
>
Defined in: packages/core/src/blockchain/index.ts:409
Build a new block with optional params. Use this when you don't have all the BuildBlockParams
Parameters
params?
Partial
<BuildBlockParams
>
Returns
Promise
<Block
>
newBlockWithParams()
newBlockWithParams(
params
):Promise
<Block
>
Defined in: packages/core/src/blockchain/index.ts:417
Build a new block with BuildBlockParams.
Parameters
params
Returns
Promise
<Block
>
onNewBlock()
onNewBlock(
block
):Promise
<void
>
Defined in: packages/core/src/blockchain/index.ts:338
Parameters
block
Returns
Promise
<void
>
saveBlockToDB()
saveBlockToDB(
block
):Promise
<void
>
Defined in: packages/core/src/blockchain/index.ts:206
Parameters
block
Returns
Promise
<void
>
setHead()
setHead(
block
):Promise
<void
>
Defined in: packages/core/src/blockchain/index.ts:346
Set block as head.
Parameters
block
Returns
Promise
<void
>
submitDownwardMessages()
submitDownwardMessages(
dmp
):void
Defined in: packages/core/src/blockchain/index.ts:394
Parameters
dmp
Returns
void
submitExtrinsic()
submitExtrinsic(
extrinsic
):Promise
<`0x${string}`
>
Defined in: packages/core/src/blockchain/index.ts:366
Submit extrinsic to txpool.
Parameters
extrinsic
`0x${string}`
Returns
Promise
<`0x${string}`
>
submitHorizontalMessages()
submitHorizontalMessages(
id
,hrmp
):void
Defined in: packages/core/src/blockchain/index.ts:400
Parameters
id
number
hrmp
Returns
void
submitUpwardMessages()
submitUpwardMessages(
id
,ump
):void
Defined in: packages/core/src/blockchain/index.ts:388
Parameters
id
number
ump
`0x${string}`
[]
Returns
void
unregisterBlock()
unregisterBlock(
block
):Promise
<void
>
Defined in: packages/core/src/blockchain/index.ts:324
Remove block from memory and db.
Parameters
block
Returns
Promise
<void
>
upcomingBlocks()
upcomingBlocks():
Promise
<number
>
Defined in: packages/core/src/blockchain/index.ts:425
Get the upcoming blocks.
Returns
Promise
<number
>
validateExtrinsic()
validateExtrinsic(
extrinsic
,source
):Promise
<TransactionValidity
>
Defined in: packages/core/src/blockchain/index.ts:378
Validate extrinsic by calling TaggedTransactionQueue_validate_transaction
.
Parameters
extrinsic
`0x${string}`
source
"0x00"
| "0x01"
| "0x02"
Returns
Promise
<TransactionValidity
>