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

Commit a924a1f

Browse files
authored
feat(chain): Arweave integration (#262)
* feat(chain): add basic arweave types * feat(global): register arweave typeIds * chore(types): use Bytes for BigInt types * feat(chain): update typeId and type of Arweave block * feat(chain): add TransactionWithBlockPtr in arweave * feat(global): register Arweave types in id_of_type * fix(global): clean typo * test(test.js): imports chain/arweave.ts in test.js * chore(global): update annotations of arweave types * chore(linter): make linter happy * chore(chain): imports Bytes from collection.ts
1 parent 4c064a8 commit a924a1f

File tree

4 files changed

+117
-1
lines changed

4 files changed

+117
-1
lines changed

chain/arweave.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import '../common/eager_offset'
2+
import { Bytes } from '../common/collections'
3+
4+
// Most types from this namespace are direct mappings or adaptations from:
5+
// https://github.com/ChainSafe/firehose-arweave/blob/master/proto/sf/arweave/type/v1/type.proto
6+
export namespace arweave {
7+
/**
8+
* A key-value pair for arbitrary metadata
9+
*/
10+
export class Tag {
11+
constructor(public name: Bytes, public value: Bytes) {}
12+
}
13+
14+
export class ProofOfAccess {
15+
constructor(
16+
public option: string,
17+
public txPath: Bytes,
18+
public dataPath: Bytes,
19+
public chunk: Bytes,
20+
) {}
21+
}
22+
23+
/**
24+
* An Arweave block.
25+
*/
26+
export class Block {
27+
constructor(
28+
public timestamp: u64,
29+
public lastRetarget: u64,
30+
public height: u64,
31+
public indepHash: Bytes,
32+
public nonce: Bytes,
33+
public previousBlock: Bytes,
34+
public diff: Bytes,
35+
public hash: Bytes,
36+
public txRoot: Bytes,
37+
public txs: Bytes[],
38+
public walletList: Bytes,
39+
public rewardAddr: Bytes,
40+
public tags: Tag[],
41+
public rewardPool: Bytes,
42+
public weaveSize: Bytes,
43+
public blockSize: Bytes,
44+
public cumulativeDiff: Bytes,
45+
public hashListMerkle: Bytes,
46+
public poa: ProofOfAccess,
47+
) {}
48+
}
49+
50+
/**
51+
* An Arweave transaction
52+
*/
53+
export class Transaction {
54+
constructor(
55+
public format: u32,
56+
public id: Bytes,
57+
public lastTx: Bytes,
58+
public owner: Bytes,
59+
public tags: Tag[],
60+
public target: Bytes,
61+
public quantity: Bytes,
62+
public data: Bytes,
63+
public dataSize: Bytes,
64+
public dataRoot: Bytes,
65+
public signature: Bytes,
66+
public reward: Bytes,
67+
) {}
68+
}
69+
70+
/**
71+
* An Arweave transaction with block ptr
72+
*/
73+
export class TransactionWithBlockPtr {
74+
constructor(public tx: Transaction, public block: Block) {}
75+
}
76+
}

global/global.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Wrapped,
99
} from '../common/collections'
1010
import { JSONValue, Value } from '../common/value'
11+
import { arweave } from '../chain/arweave'
1112
import { ethereum } from '../chain/ethereum'
1213
import { near } from '../chain/near'
1314
import { cosmos } from '../chain/cosmos'
@@ -216,7 +217,25 @@ export enum TypeId {
216217
```
217218
*/
218219

219-
// Reserved discriminant space for a future blockchain type IDs: [2,500, 3,499]
220+
// Reserved discriminant space for Tendermint type IDs: [2,500, 3,499]
221+
ArweaveBlock = 2500,
222+
ArweaveProofOfAccess = 2501,
223+
ArweaveTag = 2502,
224+
ArweaveTagArray = 2503,
225+
ArweaveTransaction = 2504,
226+
ArweaveTransactionArray = 2505,
227+
ArweaveTransactionWithBlockPtr = 2506,
228+
/*
229+
Continue to add more Arweave type IDs here. e.g.:
230+
```
231+
NextArweaveType = 2507,
232+
AnotherArweaveType = 2508,
233+
...
234+
LastArweaveType = 3499,
235+
```
236+
*/
237+
238+
// Reserved discriminant space for a future blockchain type IDs: [3,500, 4,499]
220239
}
221240

222241
export function id_of_type(typeId: TypeId): usize {
@@ -528,6 +547,23 @@ export function id_of_type(typeId: TypeId): usize {
528547
return idof<cosmos.ValidatorUpdate>()
529548
case TypeId.CosmosVersionParams:
530549
return idof<cosmos.VersionParams>()
550+
/**
551+
* Arweave type ids
552+
*/
553+
case TypeId.ArweaveBlock:
554+
return idof<arweave.Block>()
555+
case TypeId.ArweaveProofOfAccess:
556+
return idof<arweave.ProofOfAccess>()
557+
case TypeId.ArweaveTag:
558+
return idof<arweave.Tag>()
559+
case TypeId.ArweaveTagArray:
560+
return idof<Array<arweave.Tag>>()
561+
case TypeId.ArweaveTransaction:
562+
return idof<arweave.Transaction>()
563+
case TypeId.ArweaveTransactionArray:
564+
return idof<Array<arweave.Transaction>>()
565+
case TypeId.ArweaveTransactionWithBlockPtr:
566+
return idof<arweave.TransactionWithBlockPtr>()
531567
default:
532568
return 0
533569
}

index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Side-effect to evaluate eagerly the offset of stub AS runtime
22
import './common/eager_offset'
3+
// Arweave support
4+
export * from './chain/arweave'
35
// Ethereum support
46
export * from './chain/ethereum'
57
// NEAR support

test/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ async function main() {
2929
fs.copyFileSync('common/json.ts', 'test/temp_lib/common/json.ts')
3030
fs.copyFileSync('common/numbers.ts', 'test/temp_lib/common/numbers.ts')
3131
fs.copyFileSync('common/value.ts', 'test/temp_lib/common/value.ts')
32+
fs.copyFileSync('chain/arweave.ts', 'test/temp_lib/chain/arweave.ts')
3233
fs.copyFileSync('chain/ethereum.ts', 'test/temp_lib/chain/ethereum.ts')
3334
fs.copyFileSync('chain/near.ts', 'test/temp_lib/chain/near.ts')
3435
fs.copyFileSync('chain/cosmos.ts', 'test/temp_lib/chain/cosmos.ts')
@@ -62,6 +63,7 @@ async function main() {
6263
fs.unlinkSync('test/temp_lib/common/numbers.ts')
6364
fs.unlinkSync('test/temp_lib/common/value.ts')
6465
fs.rmdirSync('test/temp_lib/common')
66+
fs.unlinkSync('test/temp_lib/chain/arweave.ts')
6567
fs.unlinkSync('test/temp_lib/chain/ethereum.ts')
6668
fs.unlinkSync('test/temp_lib/chain/near.ts')
6769
fs.unlinkSync('test/temp_lib/chain/cosmos.ts')

0 commit comments

Comments
 (0)