diff --git a/chain/arweave.ts b/chain/arweave.ts new file mode 100644 index 0000000..390af08 --- /dev/null +++ b/chain/arweave.ts @@ -0,0 +1,76 @@ +import '../common/eager_offset' +import { Bytes } from '../common/collections' + +// Most types from this namespace are direct mappings or adaptations from: +// https://github.com/ChainSafe/firehose-arweave/blob/master/proto/sf/arweave/type/v1/type.proto +export namespace arweave { + /** + * A key-value pair for arbitrary metadata + */ + export class Tag { + constructor(public name: Bytes, public value: Bytes) {} + } + + export class ProofOfAccess { + constructor( + public option: string, + public txPath: Bytes, + public dataPath: Bytes, + public chunk: Bytes, + ) {} + } + + /** + * An Arweave block. + */ + export class Block { + constructor( + public timestamp: u64, + public lastRetarget: u64, + public height: u64, + public indepHash: Bytes, + public nonce: Bytes, + public previousBlock: Bytes, + public diff: Bytes, + public hash: Bytes, + public txRoot: Bytes, + public txs: Bytes[], + public walletList: Bytes, + public rewardAddr: Bytes, + public tags: Tag[], + public rewardPool: Bytes, + public weaveSize: Bytes, + public blockSize: Bytes, + public cumulativeDiff: Bytes, + public hashListMerkle: Bytes, + public poa: ProofOfAccess, + ) {} + } + + /** + * An Arweave transaction + */ + export class Transaction { + constructor( + public format: u32, + public id: Bytes, + public lastTx: Bytes, + public owner: Bytes, + public tags: Tag[], + public target: Bytes, + public quantity: Bytes, + public data: Bytes, + public dataSize: Bytes, + public dataRoot: Bytes, + public signature: Bytes, + public reward: Bytes, + ) {} + } + + /** + * An Arweave transaction with block ptr + */ + export class TransactionWithBlockPtr { + constructor(public tx: Transaction, public block: Block) {} + } +} diff --git a/global/global.ts b/global/global.ts index 4ea2cc0..576e7f0 100644 --- a/global/global.ts +++ b/global/global.ts @@ -8,6 +8,7 @@ import { Wrapped, } from '../common/collections' import { JSONValue, Value } from '../common/value' +import { arweave } from '../chain/arweave' import { ethereum } from '../chain/ethereum' import { near } from '../chain/near' import { cosmos } from '../chain/cosmos' @@ -216,7 +217,25 @@ export enum TypeId { ``` */ - // Reserved discriminant space for a future blockchain type IDs: [2,500, 3,499] + // Reserved discriminant space for Tendermint type IDs: [2,500, 3,499] + ArweaveBlock = 2500, + ArweaveProofOfAccess = 2501, + ArweaveTag = 2502, + ArweaveTagArray = 2503, + ArweaveTransaction = 2504, + ArweaveTransactionArray = 2505, + ArweaveTransactionWithBlockPtr = 2506, + /* + Continue to add more Arweave type IDs here. e.g.: + ``` + NextArweaveType = 2507, + AnotherArweaveType = 2508, + ... + LastArweaveType = 3499, + ``` + */ + + // Reserved discriminant space for a future blockchain type IDs: [3,500, 4,499] } export function id_of_type(typeId: TypeId): usize { @@ -528,6 +547,23 @@ export function id_of_type(typeId: TypeId): usize { return idof() case TypeId.CosmosVersionParams: return idof() + /** + * Arweave type ids + */ + case TypeId.ArweaveBlock: + return idof() + case TypeId.ArweaveProofOfAccess: + return idof() + case TypeId.ArweaveTag: + return idof() + case TypeId.ArweaveTagArray: + return idof>() + case TypeId.ArweaveTransaction: + return idof() + case TypeId.ArweaveTransactionArray: + return idof>() + case TypeId.ArweaveTransactionWithBlockPtr: + return idof() default: return 0 } diff --git a/index.ts b/index.ts index 9f18ccd..b5a0b50 100644 --- a/index.ts +++ b/index.ts @@ -1,5 +1,7 @@ // Side-effect to evaluate eagerly the offset of stub AS runtime import './common/eager_offset' +// Arweave support +export * from './chain/arweave' // Ethereum support export * from './chain/ethereum' // NEAR support diff --git a/test/test.js b/test/test.js index f0dc167..8071bbf 100644 --- a/test/test.js +++ b/test/test.js @@ -29,6 +29,7 @@ async function main() { fs.copyFileSync('common/json.ts', 'test/temp_lib/common/json.ts') fs.copyFileSync('common/numbers.ts', 'test/temp_lib/common/numbers.ts') fs.copyFileSync('common/value.ts', 'test/temp_lib/common/value.ts') + fs.copyFileSync('chain/arweave.ts', 'test/temp_lib/chain/arweave.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/cosmos.ts', 'test/temp_lib/chain/cosmos.ts') @@ -62,6 +63,7 @@ async function main() { fs.unlinkSync('test/temp_lib/common/numbers.ts') fs.unlinkSync('test/temp_lib/common/value.ts') fs.rmdirSync('test/temp_lib/common') + fs.unlinkSync('test/temp_lib/chain/arweave.ts') fs.unlinkSync('test/temp_lib/chain/ethereum.ts') fs.unlinkSync('test/temp_lib/chain/near.ts') fs.unlinkSync('test/temp_lib/chain/cosmos.ts')