Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

feat(chain): Arweave integration #262

Merged
merged 13 commits into from
May 16, 2022
79 changes: 79 additions & 0 deletions chain/arweave.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import '../common/eager_offset'
import { Bytes } from '..'
clearloop marked this conversation as resolved.
Show resolved Hide resolved

// 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,
) {}
}
}
35 changes: 34 additions & 1 deletion global/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { tendermint } from '../chain/tendermint'
Expand Down Expand Up @@ -201,7 +202,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 = 1547,
AnotherArweaveType = 1547,
...
LastArweaveType = 2499,
clearloop marked this conversation as resolved.
Show resolved Hide resolved
```
*/

// Reserved discriminant space for a future blockchain type IDs: [3,500, 4,499]
}

export function id_of_type(typeId: TypeId): usize {
evaporei marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -483,6 +502,20 @@ export function id_of_type(typeId: TypeId): usize {
return idof<Array<Uint8Array>>()
case TypeId.ArrayLog:
return idof<Array<ethereum.Log>>()
case TypeId.ArweaveBlock:
return idof<arweave.Block>()
case TypeId.ArweaveProofOfAccess:
return idof<arweave.ProofOfAccess>()
case TypeId.ArweaveTag:
return idof<arweave.Tag>()
case TypeId.ArweaveTagArray:
return idof<Array<arweave.Tag>>()
case TypeId.ArweaveTransaction:
return idof<arweave.Transaction>()
case TypeId.ArweaveTransactionArray:
return idof<Array<arweave.Transaction>>()
case TypeId.ArweaveTransactionWithBlockPtr:
return idof<arweave.TransactionWithBlockPtr>()
default:
return 0
}
Expand Down
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down