diff --git a/chain/tendermint.ts b/chain/tendermint.ts new file mode 100644 index 0000000..faf6ca5 --- /dev/null +++ b/chain/tendermint.ts @@ -0,0 +1,554 @@ +import '../common/eager_offset' +import { Bytes } from '../common/collections' + +export namespace tendermint { + export enum SignedMsgType { + SIGNED_MSG_TYPE_UNKNOWN = 0, + SIGNED_MSG_TYPE_PREVOTE = 1, + SIGNED_MSG_TYPE_PRECOMMIT = 2, + SIGNED_MSG_TYPE_PROPOSAL = 32, + } + + export enum BlockIDFlag { + BLOCK_ID_FLAG_UNKNOWN = 0, + BLOCK_ID_FLAG_ABSENT = 1, + BLOCK_ID_FLAG_COMMIT = 2, + BLOCK_ID_FLAG_NIL = 3, + } + + export class EventList { + public newBlock: EventBlock + public transaction: Array + public validatorSetUpdates: EventValidatorSetUpdates + + constructor( + newBlock: EventBlock, + transaction: Array, + validatorSetUpdates: EventValidatorSetUpdates, + ) { + this.newBlock = newBlock + this.transaction = transaction + this.validatorSetUpdates = validatorSetUpdates + } + } + + export class EventData { + public event: Event + public block: EventBlock + + constructor(event: Event, block: EventBlock) { + this.event = event + this.block = block + } + } + + export class Block { + public header: Header + public data: Data + public evidence: EvidenceList + public lastCommit: Commit + + constructor(header: Header, data: Data, evidence: EvidenceList, lastCommit: Commit) { + this.header = header + this.data = data + this.evidence = evidence + this.lastCommit = lastCommit + } + } + + export class BlockID { + public hash: Bytes + public partSetHeader: PartSetHeader + + constructor(hash: Bytes, partSetHeader: PartSetHeader) { + this.hash = hash + this.partSetHeader = partSetHeader + } + } + + export class BlockParams { + public maxBytes: i64 + public maxGas: i64 + + constructor(maxBytes: i64, maxGas: i64) { + this.maxBytes = maxBytes + this.maxGas = maxGas + } + } + + export class Commit { + public height: i64 + public round: i32 + public blockId: BlockID + public signatures: Array + + constructor(height: i64, round: i32, blockId: BlockID, signatures: Array) { + this.height = height + this.round = round + this.blockId = blockId + this.signatures = signatures + } + } + + export class CommitSig { + public blockIdFlag: BlockIDFlag + public validatorAddress: Bytes + public timestamp: Timestamp + public signature: Bytes + + constructor( + blockIdFlag: BlockIDFlag, + validatorAddress: Bytes, + timestamp: Timestamp, + signature: Bytes, + ) { + this.blockIdFlag = blockIdFlag + this.validatorAddress = validatorAddress + this.timestamp = timestamp + this.signature = signature + } + } + + export class Consensus { + public block: u64 + public app: u64 + + constructor(block: u64, app: u64) { + this.block = block + this.app = app + } + } + + export class ConsensusParams { + public block: BlockParams + public evidence: EvidenceParams + public validator: ValidatorParams + public version: VersionParams + + constructor( + block: BlockParams, + evidence: EvidenceParams, + validator: ValidatorParams, + version: VersionParams, + ) { + this.block = block + this.evidence = evidence + this.validator = validator + this.version = version + } + } + + export class Data { + public txs: Array + + constructor(txs: Array) { + this.txs = txs + } + } + + export class Duration { + public seconds: i64 + public nanos: i32 + + constructor(seconds: i64, nanos: i32) { + this.seconds = seconds + this.nanos = nanos + } + } + + export class DuplicateVoteEvidence { + public voteA: EventVote + public voteB: EventVote + public totalVotingPower: i64 + public validatorPower: i64 + public timestamp: Timestamp + + constructor( + voteA: EventVote, + voteB: EventVote, + totalVotingPower: i64, + validatorPower: i64, + timestamp: Timestamp, + ) { + this.voteA = voteA + this.voteB = voteB + this.totalVotingPower = totalVotingPower + this.validatorPower = validatorPower + this.timestamp = timestamp + } + } + + export class Event { + public eventType: string + public attributes: Array + + constructor(eventType: string, attributes: Array) { + this.eventType = eventType + this.attributes = attributes + } + } + + export class EventAttribute { + public key: string + public value: string + public index: bool + + constructor(key: string, value: string, index: bool) { + this.key = key + this.value = value + this.index = index + } + } + + export class EventBlock { + public block: Block + public blockId: BlockID + public resultBeginBlock: ResponseBeginBlock + public resultEndBlock: ResponseEndBlock + + constructor( + block: Block, + blockId: BlockID, + resultBeginBlock: ResponseBeginBlock, + resultEndBlock: ResponseEndBlock, + ) { + this.block = block + this.blockId = blockId + this.resultBeginBlock = resultBeginBlock + this.resultEndBlock = resultEndBlock + } + } + + export class EventTx { + public txResult: TxResult + + constructor(txResult: TxResult) { + this.txResult = txResult + } + } + + export class EventValidatorSetUpdates { + public validatorUpdates: Array + + constructor(validatorUpdates: Array) { + this.validatorUpdates = validatorUpdates + } + } + + export class EventVote { + public eventVoteType: SignedMsgType + public height: u64 + public round: i32 + public blockId: BlockID + public timestamp: Timestamp + public validatorAddress: Bytes + public validatorIndex: i32 + public signature: Bytes + + constructor( + eventVoteType: SignedMsgType, + height: u64, + round: i32, + blockId: BlockID, + timestamp: Timestamp, + validatorAddress: Bytes, + validatorIndex: i32, + signature: Bytes, + ) { + this.eventVoteType = eventVoteType + this.height = height + this.round = round + this.blockId = blockId + this.timestamp = timestamp + this.validatorAddress = validatorAddress + this.validatorIndex = validatorIndex + this.signature = signature + } + } + + export class Evidence { + public duplicateVoteEvidence: DuplicateVoteEvidence + public lightClientAttackEvidence: LightClientAttackEvidence + + constructor( + duplicateVoteEvidence: DuplicateVoteEvidence, + lightClientAttackEvidence: LightClientAttackEvidence, + ) { + this.duplicateVoteEvidence = duplicateVoteEvidence + this.lightClientAttackEvidence = lightClientAttackEvidence + } + } + + export class EvidenceList { + public evidence: Array + + constructor(evidence: Array) { + this.evidence = evidence + } + } + + export class EvidenceParams { + public maxAgeNumBlocks: i64 + public maxAgeDuration: Duration + public maxBytes: i64 + + constructor(maxAgeNumBlocks: i64, maxAgeDuration: Duration, maxBytes: i64) { + this.maxAgeNumBlocks = maxAgeNumBlocks + this.maxAgeDuration = maxAgeDuration + this.maxBytes = maxBytes + } + } + + export class Header { + public version: Consensus + public chainId: string + public height: u64 + public time: Timestamp + public lastBlockId: BlockID + public lastCommitHash: Bytes + public dataHash: Bytes + public validatorsHash: Bytes + public nextValidatorsHash: Bytes + public consensusHash: Bytes + public appHash: Bytes + public lastResultsHash: Bytes + public evidenceHash: Bytes + public proposerAddress: Bytes + + constructor( + version: Consensus, + chainId: string, + height: u64, + time: Timestamp, + lastBlockId: BlockID, + lastCommitHash: Bytes, + dataHash: Bytes, + validatorsHash: Bytes, + nextValidatorsHash: Bytes, + consensusHash: Bytes, + appHash: Bytes, + lastResultsHash: Bytes, + evidenceHash: Bytes, + proposerAddress: Bytes, + ) { + this.version = version + this.chainId = chainId + this.height = height + this.time = time + this.lastBlockId = lastBlockId + this.lastCommitHash = lastCommitHash + this.dataHash = dataHash + this.validatorsHash = validatorsHash + this.nextValidatorsHash = nextValidatorsHash + this.consensusHash = consensusHash + this.appHash = appHash + this.lastResultsHash = lastResultsHash + this.evidenceHash = evidenceHash + this.proposerAddress = proposerAddress + } + } + + export class LightBlock { + public signedHeader: SignedHeader + public validatorSet: ValidatorSet + + constructor(signedHeader: SignedHeader, validatorSet: ValidatorSet) { + this.signedHeader = signedHeader + this.validatorSet = validatorSet + } + } + + export class LightClientAttackEvidence { + public conflictingBlock: LightBlock + public commonHeight: i64 + public byzantineValidators: Array + public totalVotingPower: i64 + public timestamp: Timestamp + + constructor( + conflictingBlock: LightBlock, + commonHeight: i64, + byzantineValidators: Array, + totalVotingPower: i64, + timestamp: Timestamp, + ) { + this.conflictingBlock = conflictingBlock + this.commonHeight = commonHeight + this.byzantineValidators = byzantineValidators + this.totalVotingPower = totalVotingPower + this.timestamp = timestamp + } + } + + export class PublicKey { + public ed25519: Bytes + public secp256k1: Bytes + + constructor(ed25519: Bytes, secp256k1: Bytes) { + this.ed25519 = ed25519 + this.secp256k1 = secp256k1 + } + } + + export class PartSetHeader { + public total: u32 + public hash: Bytes + + constructor(total: u32, hash: Bytes) { + this.total = total + this.hash = hash + } + } + + export class ResponseBeginBlock { + public events: Array + + constructor(events: Array) { + this.events = events + } + } + + export class ResponseEndBlock { + public validatorUpdates: Array + public consensusParamUpdates: ConsensusParams + public events: Array + + constructor( + validatorUpdates: Array, + consensusParamUpdates: ConsensusParams, + events: Array, + ) { + this.validatorUpdates = validatorUpdates + this.consensusParamUpdates = consensusParamUpdates + this.events = events + } + } + + export class ResponseDeliverTx { + public code: u32 + public data: Bytes + public log: string + public info: string + public gasWanted: i64 + public gasUsed: i64 + public events: Array + public codespace: string + + constructor( + code: u32, + data: Bytes, + log: string, + info: string, + gasWanted: i64, + gasUsed: i64, + events: Array, + codespace: string, + ) { + this.code = code + this.data = data + this.log = log + this.info = info + this.gasWanted = gasWanted + this.gasUsed = gasUsed + this.events = events + this.codespace = codespace + } + } + + export class SignedHeader { + public header: Header + public commit: Commit + + constructor(header: Header, commit: Commit) { + this.header = header + this.commit = commit + } + } + + export class Timestamp { + public seconds: i64 + public nanos: i32 + + constructor(seconds: i64, nanos: i32) { + this.seconds = seconds + this.nanos = nanos + } + } + + export class TxResult { + public height: u64 + public index: u32 + public tx: Bytes + public result: ResponseDeliverTx + + constructor(height: u64, index: u32, tx: Bytes, result: ResponseDeliverTx) { + this.height = height + this.index = index + this.tx = tx + this.result = result + } + } + + export class Validator { + public address: Bytes + public pubKey: PublicKey + public votingPower: i64 + public proposerPriority: i64 + + constructor( + address: Bytes, + pubKey: PublicKey, + votingPower: i64, + proposerPriority: i64, + ) { + this.address = address + this.pubKey = pubKey + this.votingPower = votingPower + this.proposerPriority = proposerPriority + } + } + + export class ValidatorParams { + public pubKeyTypes: Array + + constructor(pubKeyTypes: Array) { + this.pubKeyTypes = pubKeyTypes + } + } + + export class ValidatorSet { + public validators: Array + public proposer: Validator + public totalVotingPower: i64 + + constructor( + validators: Array, + proposer: Validator, + totalVotingPower: i64, + ) { + this.validators = validators + this.proposer = proposer + this.totalVotingPower = totalVotingPower + } + } + + export class ValidatorUpdate { + public address: Bytes + public pubKey: PublicKey + public power: i64 + + constructor(address: Bytes, pubKey: PublicKey, power: i64) { + this.address = address + this.pubKey = pubKey + this.power = power + } + } + + export class VersionParams { + public appVersion: u64 + + constructor(appVersion: u64) { + this.appVersion = appVersion + } + } +} diff --git a/global/global.ts b/global/global.ts index 7f0b233..2c92773 100644 --- a/global/global.ts +++ b/global/global.ts @@ -1,8 +1,16 @@ import { BigDecimal } from '../common/numbers' -import { TypedMapEntry, Entity, TypedMap, Result, Wrapped } from '../common/collections' +import { + Bytes, + TypedMapEntry, + Entity, + TypedMap, + Result, + Wrapped, +} from '../common/collections' import { JSONValue, Value } from '../common/value' import { ethereum } from '../chain/ethereum' import { near } from '../chain/near' +import { tendermint } from '../chain/tendermint' export enum TypeId { String = 0, @@ -92,6 +100,53 @@ export enum TypeId { NearChunkHeader = 84, NearBlock = 85, NearReceiptWithOutcome = 86, + TendermintArrayEventTx = 87, + TendermintArrayEvent = 88, + TendermintArrayCommitSig = 89, + TendermintArrayBytes = 90, + TendermintArrayEvidence = 91, + TendermintArrayEventAttribute = 92, + TendermintBlockIDFlagEnum = 93, + TendermintSignedMsgTypeEnum = 94, + TendermintEventList = 95, + TendermintEventBlock = 96, + TendermintResponseBeginBlock = 97, + TendermintResponseEndBlock = 98, + TendermintValidatorUpdate = 99, + TendermintArrayValidatorUpdate = 100, + TendermintConsensusParams = 101, + TendermintBlockParams = 102, + TendermintEvidenceParams = 103, + TendermintValidatorParams = 104, + TendermintVersionParams = 105, + TendermintBlock = 106, + TendermintCommit = 107, + TendermintCommitSig = 108, + TendermintHeader = 109, + TendermintConsensus = 110, + TendermintBlockID = 111, + TendermintPartSetHeader = 112, + TendermintData = 113, + TendermintEvidence = 114, + TendermintDuplicateVoteEvidence = 115, + TendermintEventTx = 116, + TendermintEventVote = 117, + TendermintLightClientAttackEvidence = 118, + TendermintLightBlock = 119, + TendermintValidatorSet = 120, + TendermintSignedHeader = 121, + TendermintEvidenceList = 122, + TendermintValidator = 123, + TendermintArrayValidator = 124, + TendermintPublicKey = 125, + TendermintTxResult = 126, + TendermintResponseDeliverTx = 127, + TendermintEvent = 128, + TendermintEventAttribute = 129, + TendermintEventValidatorSetUpdates = 130, + TendermintDuration = 131, + TendermintTimestamp = 132, + TendermintEventData = 133, } export function id_of_type(typeId: TypeId): usize { @@ -271,6 +326,100 @@ export function id_of_type(typeId: TypeId): usize { return idof() case TypeId.NearReceiptWithOutcome: return idof() + case TypeId.TendermintArrayEventTx: + return idof>() + case TypeId.TendermintArrayEvent: + return idof>() + case TypeId.TendermintArrayCommitSig: + return idof>() + case TypeId.TendermintArrayBytes: + return idof>() + case TypeId.TendermintArrayEvidence: + return idof>() + case TypeId.TendermintArrayEventAttribute: + return idof>() + case TypeId.TendermintBlockIDFlagEnum: + return idof>() + case TypeId.TendermintSignedMsgTypeEnum: + return idof>() + case TypeId.TendermintEventList: + return idof() + case TypeId.TendermintEventBlock: + return idof() + case TypeId.TendermintResponseBeginBlock: + return idof() + case TypeId.TendermintResponseEndBlock: + return idof() + case TypeId.TendermintValidatorUpdate: + return idof() + case TypeId.TendermintArrayValidatorUpdate: + return idof>() + case TypeId.TendermintConsensusParams: + return idof() + case TypeId.TendermintBlockParams: + return idof() + case TypeId.TendermintEvidenceParams: + return idof() + case TypeId.TendermintValidatorParams: + return idof() + case TypeId.TendermintVersionParams: + return idof() + case TypeId.TendermintBlock: + return idof() + case TypeId.TendermintCommit: + return idof() + case TypeId.TendermintCommitSig: + return idof() + case TypeId.TendermintHeader: + return idof() + case TypeId.TendermintConsensus: + return idof() + case TypeId.TendermintBlockID: + return idof() + case TypeId.TendermintPartSetHeader: + return idof() + case TypeId.TendermintData: + return idof() + case TypeId.TendermintEvidence: + return idof() + case TypeId.TendermintDuplicateVoteEvidence: + return idof() + case TypeId.TendermintEventTx: + return idof() + case TypeId.TendermintEventVote: + return idof() + case TypeId.TendermintLightClientAttackEvidence: + return idof() + case TypeId.TendermintLightBlock: + return idof() + case TypeId.TendermintValidatorSet: + return idof() + case TypeId.TendermintSignedHeader: + return idof() + case TypeId.TendermintEvidenceList: + return idof() + case TypeId.TendermintValidator: + return idof() + case TypeId.TendermintArrayValidator: + return idof>() + case TypeId.TendermintPublicKey: + return idof() + case TypeId.TendermintTxResult: + return idof() + case TypeId.TendermintResponseDeliverTx: + return idof() + case TypeId.TendermintEvent: + return idof() + case TypeId.TendermintEventAttribute: + return idof() + case TypeId.TendermintEventValidatorSetUpdates: + return idof() + case TypeId.TendermintDuration: + return idof() + case TypeId.TendermintTimestamp: + return idof() + case TypeId.TendermintEventData: + return idof() default: return 0 } diff --git a/index.ts b/index.ts index 438a289..c8f3fa4 100644 --- a/index.ts +++ b/index.ts @@ -4,6 +4,8 @@ import './common/eager_offset' export * from './chain/ethereum' // NEAR support export * from './chain/near' +// Tendermint support +export * from './chain/tendermint' // Regular re-exports export * from './common/numbers' export * from './common/collections' diff --git a/test/test.js b/test/test.js index 60e538c..916b05c 100644 --- a/test/test.js +++ b/test/test.js @@ -31,6 +31,7 @@ async function main() { fs.copyFileSync('common/value.ts', 'test/temp_lib/common/value.ts') fs.copyFileSync('chain/ethereum.ts', 'test/temp_lib/chain/ethereum.ts') fs.copyFileSync('chain/near.ts', 'test/temp_lib/chain/near.ts') + fs.copyFileSync('chain/tendermint.ts', 'test/temp_lib/chain/tendermint.ts') fs.copyFileSync('index.ts', 'test/temp_lib/index.ts') try { @@ -63,6 +64,7 @@ async function main() { fs.rmdirSync('test/temp_lib/common') fs.unlinkSync('test/temp_lib/chain/ethereum.ts') fs.unlinkSync('test/temp_lib/chain/near.ts') + fs.unlinkSync('test/temp_lib/chain/tendermint.ts') fs.rmdirSync('test/temp_lib/chain') fs.unlinkSync('test/temp_lib/index.ts') fs.rmdirSync('test/temp_lib')