Skip to content

Commit

Permalink
wip: feat(namada): decoding transactions from rust/wasm, pt.1
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus committed Mar 12, 2024
1 parent 855cf1a commit 110d6e5
Show file tree
Hide file tree
Showing 17 changed files with 1,094 additions and 864 deletions.
2 changes: 2 additions & 0 deletions packages/cw/cw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export {
encodeSecp256k1Signature
} from './cw-identity'
export * from './cw-chains'
export * as Staking from './cw-staking'
export { Core }

export default class CWCLI extends CLI {

Expand Down
1 change: 1 addition & 0 deletions packages/namada/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/namada/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ wasm-bindgen = "0.2.86"
#wasm-bindgen-rayon = { version = "1.0", optional = true }
#console_error_panic_hook = "0.1.6"
#zeroize = "1.6.0"
#hex = "0.4.3"
hex = "0.4.3"

#[dependencies.web-sys]
#version = "0.3.4"
Expand Down
28 changes: 22 additions & 6 deletions packages/namada/namada-connection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Address } from '@fadroma/agent'
import { CWConnection } from '../cw-connection'
import * as CW from '@fadroma/cw'
//import * as WASM from './pkg/fadroma_namada.js'
//console.log({WASM})
import init, { Decode } from './pkg/fadroma_namada.js'

Check failure on line 4 in packages/namada/namada-connection.ts

View workflow job for this annotation

GitHub Actions / PNPM CI

Cannot find module './pkg/fadroma_namada.js' or its corresponding type declarations.
import {
getTotalStaked,
getStakingParameters,
Expand All @@ -25,7 +27,21 @@ import {
isPGFSteward
} from "./namada-pgf"

export class NamadaConnection extends CWConnection {
export async function connect (optionsWithDecoder: ConstructorParameters<typeof NamadaConnection>[0] & {
decoder: string|URL|Uint8Array
}) {
let { decoder, ...options } = optionsWithDecoder
if (decoder instanceof Uint8Array) {
await init(decoder)
} else if (decoder) {
await init(await fetch(decoder))
}
return new NamadaConnection(options)
}

export class NamadaConnection extends CW.Connection {

decode = Decode

getPGFParameters () {
return getPGFParameters(this)
Expand All @@ -39,7 +55,7 @@ export class NamadaConnection extends CWConnection {
return getPGFFundings(this)
}

isPGFSteward (address: Address) {
isPGFSteward (address: CW.Core.Address) {

Check failure on line 58 in packages/namada/namada-connection.ts

View workflow job for this annotation

GitHub Actions / PNPM CI

Namespace '"/home/runner/work/fadroma/fadroma/packages/agent/core"' has no exported member 'Address'.
return isPGFSteward(this)
}

Expand Down Expand Up @@ -68,7 +84,7 @@ export class NamadaConnection extends CWConnection {
return getValidatorsBelowCapacity(this)
}

getValidator (address: Address) {
getValidator (address: CW.Core.Address) {

Check failure on line 87 in packages/namada/namada-connection.ts

View workflow job for this annotation

GitHub Actions / PNPM CI

Namespace '"/home/runner/work/fadroma/fadroma/packages/agent/core"' has no exported member 'Address'.
return getValidator(this, address)
}

Expand All @@ -92,7 +108,7 @@ export class NamadaConnection extends CWConnection {
return getTotalStaked(this)
}

getValidatorStake(address: Address) {
getValidatorStake(address: CW.Core.Address) {

Check failure on line 111 in packages/namada/namada-connection.ts

View workflow job for this annotation

GitHub Actions / PNPM CI

Namespace '"/home/runner/work/fadroma/fadroma/packages/agent/core"' has no exported member 'Address'.
return getValidatorStake(this, address)
}
}
11 changes: 2 additions & 9 deletions packages/namada/namada-epoch.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import * as Borsher from 'borsher'
import { decode, struct, u64 } from '@hackbg/borshest'

const Schema = Borsher.BorshSchema
import { decode, u64 } from '@hackbg/borshest'

type Connection = { abciQuery: (path: string) => Promise<Uint8Array> }

export async function getCurrentEpoch (connection: Connection) {
const binary = await connection.abciQuery("/shell/epoch")
return decode(epochSchema, binary)
return decode(u64, binary)
}

const epochSchema = struct(
["epoch", u64]
)
Loading

0 comments on commit 110d6e5

Please sign in to comment.