mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-06-16 18:19:17 +08:00
feat: client draft
This commit is contained in:
9
components/client/typescript/.editorconfig
Normal file
9
components/client/typescript/.editorconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[{*.ts,*.json}]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
14211
components/client/typescript/package-lock.json
generated
Normal file
14211
components/client/typescript/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
43
components/client/typescript/package.json
Normal file
43
components/client/typescript/package.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "@hirosystems/chainhook-client",
|
||||
"version": "1.0.0",
|
||||
"description": "TS client for Chainhook",
|
||||
"main": "./dist/index.js",
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/hirosystems/chainhook.git"
|
||||
},
|
||||
"keywords": [
|
||||
"client",
|
||||
"types"
|
||||
],
|
||||
"author": "Hiro Systems PBC <engineering@hiro.so> (https://hiro.so)",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/hirosystems/chainhook/issues"
|
||||
},
|
||||
"homepage": "https://github.com/hirosystems/chainhook#readme",
|
||||
"devDependencies": {
|
||||
"@stacks/eslint-config": "^1.2.0",
|
||||
"@types/jest": "^29.5.0",
|
||||
"@types/node": "^18.15.7",
|
||||
"@typescript-eslint/eslint-plugin": "^5.56.0",
|
||||
"@typescript-eslint/parser": "^5.56.0",
|
||||
"babel-jest": "^29.5.0",
|
||||
"eslint": "^8.36.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"eslint-plugin-tsdoc": "^0.2.17",
|
||||
"jest": "^29.5.0",
|
||||
"prettier": "^2.8.7",
|
||||
"rimraf": "^4.4.1",
|
||||
"ts-jest": "^29.0.5",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "^0.26.3"
|
||||
}
|
||||
}
|
||||
0
components/client/typescript/src/index.ts
Normal file
0
components/client/typescript/src/index.ts
Normal file
77
components/client/typescript/src/schemas/index.ts
Normal file
77
components/client/typescript/src/schemas/index.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { Static, TSchema, Type } from '@sinclair/typebox';
|
||||
import { TypeCompiler } from '@sinclair/typebox/compiler';
|
||||
|
||||
export const Nullable = <T extends TSchema>(type: T) => Type.Union([type, Type.Null()]);
|
||||
|
||||
export const BlockIdentifier = Type.Object({
|
||||
index: Type.Integer(),
|
||||
hash: Type.String(),
|
||||
});
|
||||
|
||||
export const TransactionIdentifier = Type.Object({
|
||||
hash: Type.String()
|
||||
});
|
||||
|
||||
const BitcoinOutput = Type.Object({
|
||||
value: Type.Integer(),
|
||||
script_pubkey: Type.String(),
|
||||
});
|
||||
|
||||
const InscriptionRevealed = Type.Object({
|
||||
inscription_revealed: Type.Object({
|
||||
content_bytes: Type.String(),
|
||||
content_type: Type.String(),
|
||||
content_length: Type.Integer(),
|
||||
inscription_number: Type.Integer(),
|
||||
inscription_fee: Type.Integer(),
|
||||
inscription_id: Type.String(),
|
||||
inscriber_address: Type.String(),
|
||||
ordinal_number: Type.Integer(),
|
||||
ordinal_block_height: Type.Integer(),
|
||||
ordinal_offset: Type.Integer(),
|
||||
satpoint_post_inscription: Type.String(),
|
||||
}),
|
||||
});
|
||||
|
||||
const InscriptionTransferred = Type.Object({
|
||||
inscription_transferred: Type.Object({
|
||||
inscription_number: Type.Integer(),
|
||||
inscription_id: Type.String(),
|
||||
ordinal_number: Type.Integer(),
|
||||
updated_address: Type.String(),
|
||||
satpoint_pre_transfer: Type.String(),
|
||||
satpoint_post_transfer: Type.String(),
|
||||
})
|
||||
});
|
||||
|
||||
const BitcoinTransaction = Type.Object({
|
||||
transaction_identifier: TransactionIdentifier,
|
||||
operations: Type.Array(Type.Any()),
|
||||
metadata: Type.Object({
|
||||
ordinal_operations: Type.Union([InscriptionRevealed, InscriptionTransferred]),
|
||||
outputs: Type.Array(BitcoinOutput),
|
||||
proof: Type.String(),
|
||||
}),
|
||||
});
|
||||
|
||||
const BitcoinEvent = Type.Object({
|
||||
block_identifier: BlockIdentifier,
|
||||
parent_block_identifier: BlockIdentifier,
|
||||
timestamp: Type.Integer(),
|
||||
transactions: Type.Array(BitcoinTransaction),
|
||||
metadata: Type.Any(),
|
||||
});
|
||||
|
||||
const ChainhookPayload = Type.Object({
|
||||
apply: Type.Array(BitcoinEvent),
|
||||
rollback: Type.Array(BitcoinEvent),
|
||||
chainhook: Type.Object({
|
||||
uuid: Type.String(),
|
||||
predicate: Type.Object({
|
||||
scope: Type.String(),
|
||||
ordinal: Type.String(),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
export type ChainhookPayload = Static<typeof ChainhookPayload>;
|
||||
export const ChainhookPayloadCType = TypeCompiler.Compile(ChainhookPayload);
|
||||
107
components/client/typescript/src/schemas/stacks.ts
Normal file
107
components/client/typescript/src/schemas/stacks.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import { Type } from '@sinclair/typebox';
|
||||
import { BlockIdentifier, Nullable, TransactionIdentifier } from '.';
|
||||
|
||||
const FtTransferEvent = Type.Object({
|
||||
type: Type.Literal('FTTransferEvent'),
|
||||
data: Type.Object({
|
||||
amount: Type.String(),
|
||||
asset_identifier: Type.String(),
|
||||
recipient: Type.String(),
|
||||
sender: Type.String()
|
||||
}),
|
||||
});
|
||||
|
||||
const FtMintEvent = Type.Object({
|
||||
type: Type.Literal('FTMintEvent'),
|
||||
data: Type.Object({
|
||||
amount: Type.String(),
|
||||
asset_identifier: Type.String(),
|
||||
recipient: Type.String(),
|
||||
}),
|
||||
});
|
||||
|
||||
const SmartContractEvent = Type.Object({
|
||||
type: Type.Literal('SmartContractEvent'),
|
||||
data: Type.Object({
|
||||
contract_identifier: Type.String(),
|
||||
raw_value: Type.String(),
|
||||
topic: Type.String()
|
||||
}),
|
||||
});
|
||||
|
||||
const StxTransferEvent = Type.Object({
|
||||
type: Type.Literal('STXTransferEvent'),
|
||||
data: Type.Object({
|
||||
amount: Type.String(),
|
||||
sender: Type.String(),
|
||||
recipient: Type.String(),
|
||||
})
|
||||
});
|
||||
|
||||
const StacksTransaction = Type.Object({
|
||||
transaction_identifier: TransactionIdentifier,
|
||||
operations: Type.Array(Type.Object({
|
||||
account: Type.Object({
|
||||
address: Type.String(),
|
||||
}),
|
||||
amount: Type.Object({
|
||||
currency: Type.Object({
|
||||
decimals: Type.Integer(),
|
||||
symbol: Type.String(),
|
||||
}),
|
||||
value: Type.Integer(),
|
||||
}),
|
||||
operation_identifier: Type.Object({
|
||||
index: Type.Integer(),
|
||||
}),
|
||||
related_operations: Type.Array(Type.Object({
|
||||
index: Type.Integer(),
|
||||
})),
|
||||
status: Type.String(),
|
||||
type: Type.String(),
|
||||
})),
|
||||
metadata: Type.Object({
|
||||
description: Type.String(),
|
||||
execution_cost: Type.Object({
|
||||
read_count: Type.Integer(),
|
||||
read_length: Type.Integer(),
|
||||
runtime: Type.Integer(),
|
||||
write_count: Type.Integer(),
|
||||
write_length: Type.Integer(),
|
||||
}),
|
||||
fee: Type.Integer(),
|
||||
kind: Type.Any(), // TODO
|
||||
nonce: Type.Integer(),
|
||||
position: Type.Object({
|
||||
index: Type.Integer(),
|
||||
micro_block_identifier: Type.Optional(BlockIdentifier),
|
||||
}),
|
||||
proof: Nullable(Type.String()),
|
||||
raw_tx: Type.String(),
|
||||
receipt: Type.Object({
|
||||
contract_calls_stack: Type.Array(Type.Any()),
|
||||
events: Type.Array(Type.Union([
|
||||
FtTransferEvent, FtMintEvent, SmartContractEvent, StxTransferEvent
|
||||
])),
|
||||
mutated_assets_radius: Type.Array(Type.String()),
|
||||
mutated_contracts_radius: Type.Array(Type.String()),
|
||||
}),
|
||||
result: Type.String(),
|
||||
sender: Type.String(),
|
||||
success: Type.Boolean(),
|
||||
}),
|
||||
});
|
||||
|
||||
const StacksEvent = Type.Object({
|
||||
block_identifier: BlockIdentifier,
|
||||
parent_block_identifier: BlockIdentifier,
|
||||
timestamp: Type.Integer(),
|
||||
transactions: Type.Array(StacksTransaction),
|
||||
metadata: Type.Object({
|
||||
bitcoin_anchor_block_identifier: BlockIdentifier,
|
||||
confirm_microblock_identifier: BlockIdentifier,
|
||||
pox_cycle_index: Type.Integer(),
|
||||
pox_cycle_length: Type.Integer(),
|
||||
pox_cycle_position: Type.Integer(),
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user