Skip to content

Commit

Permalink
refactor(namada): bye namada-tx-section-base, namada-tx-variant
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus committed Jun 6, 2024
1 parent e7ad52b commit 7ce6f93
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 148 deletions.
38 changes: 13 additions & 25 deletions packages/namada/namada-console.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
import { Console, bold } from '@hackbg/fadroma'
import type { Transaction } from './namada-tx-base'
import type { VoteProposal } from './namada-gov-tx'
import type Section from './namada-tx-section'
import * as Sections from './namada-tx-section'
import type {
Validator
} from './namada-pos'
import type { Validator } from './namada-pos'

export class NamadaConsole extends Console {

printTx (
{
txType, chainId, timestamp, expiration, codeHash, dataHash, memoHash, sections
}: Partial<Transaction> = {},
indent = 0
) {
this.log('-', bold(`${txType} transaction:`))
.log(' Chain ID: ', bold(chainId))
.log(' Timestamp: ', bold(timestamp))
.log(' Expiration:', bold(expiration))
.log(' Code hash: ', bold(codeHash))
.log(' Data hash: ', bold(dataHash))
.log(' Memo hash: ', bold(memoHash))
.log(' Sections: ', bold(sections?.length))
printTx (tx: Partial<Transaction> = {}, indent = 0) {
this.log('-', bold(`${tx.txType} transaction:`))
.log(' Chain ID: ', bold(tx.chainId))
.log(' Timestamp: ', bold(tx.timestamp))
.log(' Expiration:', bold(tx.expiration))
.log(' Code hash: ', bold(tx.codeHash))
.log(' Data hash: ', bold(tx.dataHash))
.log(' Memo hash: ', bold(tx.memoHash))
.log(' Sections: ', bold(tx.sections?.length))
}

printTxSections (
sections: Array<Partial<Sections.Section>> = [],
indent = 0
) {
printTxSections (sections: Array<Partial<Section>> = [], indent = 0) {
console.log(bold(' Sections: '))
for (const section of sections) {
this.printTxSection(section)
}
return true
}

printTxSection (
section: Partial<Sections.Section> = {},
indent = 0
) {
printTxSection (section: Partial<Section> = {}, indent = 0) {
switch (true) {
case (section instanceof Sections.Data):
return this.printDataSection(section)
Expand Down
95 changes: 94 additions & 1 deletion packages/namada/namada-tx-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,97 @@ class NamadaTransaction {
}
}

export { NamadaTransaction as Transaction }
export default NamadaTransaction

class NamadaUndecodedTransaction extends NamadaTransaction {
data!: unknown
error!: Error
constructor (properties: Partial<NamadaUndecodedTransaction> = {}) {
super()
assign(this, properties, [ "data", "error" ])
}
}

class NamadaRawTransaction extends NamadaTransaction {
txType = 'Raw' as 'Raw'
//constructor (header: object, details: object, sections: object[]) {
//super(header, sections)
//this.txType = 'Raw'
//}
}

class NamadaWrapperTransaction extends NamadaTransaction {
txType = 'Wrapper' as 'Wrapper'
//declare fee: {
//token: string
//amountPerGasUnit: {
//amount: bigint,
//denomination: number
//},
//}
//declare pk: string
//declare epoch: bigint
//declare gasLimit: bigint
//declare unshieldSectionHash: string|null
//constructor (header: object, details: object, sections: object[]) {
//super(header, sections)
//assignCamelCase(this, details, wrapperTransactionFields.map(x=>x[0] as string))
//this.txType = 'Wrapper'
//}

//export const wrapperTransactionFields: Fields = [
//["fee", struct(
//["amountPerGasUnit", struct(
//["amount", u256],
//["denomination", u8],
//)],
//["token", addr],
//)],
//["pk", pubkey],
//["epoch", u64],
//["gasLimit", u64],
//["unshieldSectionHash", option(hashSchema)],
//]
}

class NamadaDecryptedTransaction extends NamadaTransaction {
txType = 'Decrypted' as 'Decrypted'
//undecryptable: boolean
}

class NamadaProtocolTransaction extends NamadaTransaction {
txType = 'Protocol' as 'Protocol'
//pk: string
//tx: |'EthereumEvents'
//|'BridgePool'
//|'ValidatorSetUpdate'
//|'EthEventsVext'
//|'BridgePoolVext'
//|'ValSetUpdateVext'
//constructor (header: object, details: object, sections: object[]) {
//super(header, sections)
//assignCamelCase(this, details, protocolTransactionFields.map(x=>x[0] as string))
//this.txType = 'Protocol'
//}

//export const protocolTransactionFields: Fields = [
//["pk", pubkey],
//["tx", variants(
//['EthereumEvents', unit],
//['BridgePool', unit],
//['ValidatorSetUpdate', unit],
//['EthEventsVext', unit],
//['BridgePoolVext', unit],
//['ValSetUpdateVext', unit],
//)],
//]

}

export {
NamadaUndecodedTransaction as Undecoded,
NamadaRawTransaction as Raw,
NamadaWrapperTransaction as Wrapper,
NamadaDecryptedTransaction as Decrypted,
NamadaProtocolTransaction as Protocol,
}
20 changes: 0 additions & 20 deletions packages/namada/namada-tx-section-base.ts

This file was deleted.

21 changes: 19 additions & 2 deletions packages/namada/namada-tx-section.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import { assign } from '@hackbg/fadroma'
import type { Fields } from '@hackbg/borshest'
import { Section } from './namada-tx-section-base'

class Section {
static noun = 'Section'
type!: null
|'Data'
|'ExtraData'
|'Code'
|'Signature'
|'Ciphertext'
|'MaspTx'
|'MaspBuilder'
|'Header'
constructor (properties: Partial<Section> = {}) {
assign(this, properties, [
"type"
])
}
}

class UnknownSection extends Section {
static noun = 'Unknown Section'
Expand Down Expand Up @@ -160,8 +177,8 @@ class HeaderSection extends Section {
}
}

export default Section
export {
Section,
UnknownSection as Unknown,
DataSection as Data,
CodeSection as Code,
Expand Down
95 changes: 0 additions & 95 deletions packages/namada/namada-tx-variant.ts

This file was deleted.

9 changes: 4 additions & 5 deletions packages/namada/namada-tx.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
export { Transaction } from './namada-tx-base'
export * as Transactions from './namada-tx-variant'
export { Section } from './namada-tx-section-base'
export { default as Transaction } from './namada-tx-base'
export * as Transactions from './namada-tx-base'
export { default as Section } from './namada-tx-section'
export * as Sections from './namada-tx-section'
export { default as wasmToContent } from './namada-tx-content'
export * as Contents from './namada-tx-content'

import { Block } from '@fadroma/cw'
import { Transaction } from './namada-tx-base'
import { Decode } from './namada-decode'
import { Undecoded } from './namada-tx-variant'
import Transaction, { Undecoded } from './namada-tx-base'
import type { Namada } from './namada-connection'

export class NamadaBlock extends Block {
Expand Down

0 comments on commit 7ce6f93

Please sign in to comment.