From 1b7ce716f85bcf9d675b9e5db41598f3740c4a6c Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Mon, 11 Apr 2022 02:30:28 +0800 Subject: [PATCH 01/11] feat(chain): add basic arweave types --- chain/arweave.ts | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 chain/arweave.ts diff --git a/chain/arweave.ts b/chain/arweave.ts new file mode 100644 index 0000000..7ec1397 --- /dev/null +++ b/chain/arweave.ts @@ -0,0 +1,69 @@ +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 indepHash: Bytes, + public nonce: Bytes, + public previousBlock: Bytes, + public timestamp: u64, + public lastRetarget: u64, + public diff: string, + public height: u64, + public hash: Bytes, + public txRoot: Bytes, + public walletList: Bytes, + public rewardAddr: Bytes, + public tags: Tag[], + public rewardPool: string, + public weaveSize: string, + public blockSize: string, + public cumulativeDiff: string, + public hashList: Bytes, + public hashListMerkle: Bytes, + public poa: ProofOfAccess, + ) {} + } + + /** + * An Arweave transaction + */ + export class Transaction { + constructor( + public format: u32, + public id: string, + public lastTx: Bytes, + public owner: Bytes, + public tags: Tag[], + public target: Bytes, + public quantity: string, + public data: Bytes, + public dataSize: string, + public dataRoot: string, + public signature: Bytes, + public reward: string, + ) {} + } +} From 45317a99ef2e61470e763576a42fc30ba0516e24 Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Thu, 21 Apr 2022 20:37:53 +0800 Subject: [PATCH 02/11] feat(global): register arweave typeIds --- chain/arweave.ts | 30 +++++++++++++++--------------- global/global.ts | 8 ++++++++ index.ts | 2 ++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/chain/arweave.ts b/chain/arweave.ts index 7ec1397..0f34a08 100644 --- a/chain/arweave.ts +++ b/chain/arweave.ts @@ -1,5 +1,5 @@ import '../common/eager_offset' -import { Bytes } from '../common/collections' +import { Bytes, BigInt } from '..' // 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 @@ -25,23 +25,23 @@ export namespace arweave { */ export class Block { constructor( - public indepHash: Bytes, - public nonce: Bytes, - public previousBlock: Bytes, public timestamp: u64, public lastRetarget: u64, - public diff: string, public height: u64, + public indepHash: Bytes, + public nonce: Bytes, + public previousBlock: Bytes, + public diff: Bytes, public hash: Bytes, public txRoot: Bytes, + public txs: Transaction[], public walletList: Bytes, public rewardAddr: Bytes, public tags: Tag[], - public rewardPool: string, - public weaveSize: string, - public blockSize: string, - public cumulativeDiff: string, - public hashList: Bytes, + public rewardPool: BigInt, + public weaveSize: BigInt, + public blockSize: BigInt, + public cumulativeDiff: BigInt, public hashListMerkle: Bytes, public poa: ProofOfAccess, ) {} @@ -53,17 +53,17 @@ export namespace arweave { export class Transaction { constructor( public format: u32, - public id: string, + public id: Bytes, public lastTx: Bytes, public owner: Bytes, public tags: Tag[], public target: Bytes, - public quantity: string, + public quantity: Bytes, public data: Bytes, - public dataSize: string, - public dataRoot: string, + public dataSize: Bytes, + public dataRoot: Bytes, public signature: Bytes, - public reward: string, + public reward: Bytes, ) {} } } diff --git a/global/global.ts b/global/global.ts index e0d29a6..435d380 100644 --- a/global/global.ts +++ b/global/global.ts @@ -154,6 +154,14 @@ export enum TypeId { Log = 135, ArrayH256 = 136, ArrayLog = 137, + + // Arweave types + ArweaveBlock = 2500, + ArweaveProofOfAccess = 2501, + ArweaveTransaction = 2502, + ArweaveTransactionArray = 2503, + ArweaveTag = 2504, + ArweaveTagArray = 2505, } export function id_of_type(typeId: TypeId): usize { diff --git a/index.ts b/index.ts index c8f3fa4..51c2e72 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 From d6b1e79b8be8becd0361b0d2d5f2d66405dee23c Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Tue, 26 Apr 2022 16:58:10 +0800 Subject: [PATCH 03/11] chore(types): use Bytes for BigInt types --- chain/arweave.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/chain/arweave.ts b/chain/arweave.ts index 0f34a08..c86e0ef 100644 --- a/chain/arweave.ts +++ b/chain/arweave.ts @@ -1,5 +1,5 @@ import '../common/eager_offset' -import { Bytes, BigInt } from '..' +import { Bytes } from '..' // 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 @@ -38,10 +38,10 @@ export namespace arweave { public walletList: Bytes, public rewardAddr: Bytes, public tags: Tag[], - public rewardPool: BigInt, - public weaveSize: BigInt, - public blockSize: BigInt, - public cumulativeDiff: BigInt, + public rewardPool: Bytes, + public weaveSize: Bytes, + public blockSize: Bytes, + public cumulativeDiff: Bytes, public hashListMerkle: Bytes, public poa: ProofOfAccess, ) {} From 7d7a5d4598b4b1951b1e865ff520cce4f82f675c Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Thu, 28 Apr 2022 02:55:58 +0800 Subject: [PATCH 04/11] feat(chain): update typeId and type of Arweave block --- chain/arweave.ts | 2 +- global/global.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/chain/arweave.ts b/chain/arweave.ts index c86e0ef..a1f1da5 100644 --- a/chain/arweave.ts +++ b/chain/arweave.ts @@ -34,7 +34,7 @@ export namespace arweave { public diff: Bytes, public hash: Bytes, public txRoot: Bytes, - public txs: Transaction[], + public txs: string[], public walletList: Bytes, public rewardAddr: Bytes, public tags: Tag[], diff --git a/global/global.ts b/global/global.ts index 435d380..f7d2203 100644 --- a/global/global.ts +++ b/global/global.ts @@ -158,10 +158,11 @@ export enum TypeId { // Arweave types ArweaveBlock = 2500, ArweaveProofOfAccess = 2501, - ArweaveTransaction = 2502, - ArweaveTransactionArray = 2503, - ArweaveTag = 2504, - ArweaveTagArray = 2505, + ArweaveTag = 2502, + ArweaveTagArray = 2503, + ArweaveTransaction = 2504, + ArweaveTransactionArray = 2505, + ArweaveTransactionWithBlockPtr = 2506, } export function id_of_type(typeId: TypeId): usize { From d2739ef8afca7541ff469c73fb401cdc3f58f173 Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Thu, 28 Apr 2022 03:24:02 +0800 Subject: [PATCH 05/11] feat(chain): add TransactionWithBlockPtr in arweave --- chain/arweave.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/chain/arweave.ts b/chain/arweave.ts index a1f1da5..205cf84 100644 --- a/chain/arweave.ts +++ b/chain/arweave.ts @@ -34,7 +34,7 @@ export namespace arweave { public diff: Bytes, public hash: Bytes, public txRoot: Bytes, - public txs: string[], + public txs: Bytes[], public walletList: Bytes, public rewardAddr: Bytes, public tags: Tag[], @@ -66,4 +66,14 @@ export namespace arweave { public reward: Bytes, ) {} } + + /** + * An Arweave transaction with block ptr + */ + export class TransactionWithBlockPtr { + constructor( + public tx: Transaction, + public block: Block, + ) {} + } } From b483375700e2be6ae6ad9f8135410e6632d2d3c0 Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Fri, 6 May 2022 07:07:35 +0800 Subject: [PATCH 06/11] feat(global): register Arweave types in id_of_type --- global/global.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/global/global.ts b/global/global.ts index f7d2203..c030fb8 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 { tendermint } from '../chain/tendermint' @@ -444,6 +445,20 @@ export function id_of_type(typeId: TypeId): usize { return idof>() case TypeId.ArrayLog: return idof>() + 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 } From 23998ef10d367d988b72fc327acc109eb35cb1f7 Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Fri, 6 May 2022 07:14:52 +0800 Subject: [PATCH 07/11] fix(global): clean typo --- global/global.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/global/global.ts b/global/global.ts index 666a1af..5f825ef 100644 --- a/global/global.ts +++ b/global/global.ts @@ -210,8 +210,17 @@ export enum TypeId { ArweaveTransaction = 2504, ArweaveTransactionArray = 2505, ArweaveTransactionWithBlockPtr = 2506, + /* + Continue to add more Arweave type IDs here. e.g.: + ``` + NextArweaveType = 1547, + AnotherArweaveType = 1547, + ... + LastArweaveType = 2499, + ``` + */ + // Reserved discriminant space for a future blockchain type IDs: [3,500, 4,499] ->>>>>>> main } export function id_of_type(typeId: TypeId): usize { From ffd7577cbd393e7a56d05c11d54cb1df64b9cdd4 Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Thu, 12 May 2022 16:33:39 +0800 Subject: [PATCH 08/11] test(test.js): imports chain/arweave.ts in test.js --- test/test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test.js b/test/test.js index 916b05c..79514c2 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/tendermint.ts', 'test/temp_lib/chain/tendermint.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/tendermint.ts') From 2bd86fade63f4007189e44b48f51b31080fcf796 Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Thu, 12 May 2022 16:41:56 +0800 Subject: [PATCH 09/11] chore(global): update annotations of arweave types --- global/global.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/global/global.ts b/global/global.ts index 5f825ef..9806080 100644 --- a/global/global.ts +++ b/global/global.ts @@ -213,10 +213,10 @@ export enum TypeId { /* Continue to add more Arweave type IDs here. e.g.: ``` - NextArweaveType = 1547, - AnotherArweaveType = 1547, + NextArweaveType = 2507, + AnotherArweaveType = 2508, ... - LastArweaveType = 2499, + LastArweaveType = 3499, ``` */ From a340f824078dcd300622515a0a580e9ab91902bf Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Thu, 12 May 2022 16:55:58 +0800 Subject: [PATCH 10/11] chore(linter): make linter happy --- chain/arweave.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/chain/arweave.ts b/chain/arweave.ts index 205cf84..e76d60c 100644 --- a/chain/arweave.ts +++ b/chain/arweave.ts @@ -71,9 +71,6 @@ export namespace arweave { * An Arweave transaction with block ptr */ export class TransactionWithBlockPtr { - constructor( - public tx: Transaction, - public block: Block, - ) {} + constructor(public tx: Transaction, public block: Block) {} } } From 34e8cca727fa30e28452a0ea0c563e763916346f Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Fri, 13 May 2022 16:13:33 +0800 Subject: [PATCH 11/11] chore(chain): imports Bytes from collection.ts --- chain/arweave.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/arweave.ts b/chain/arweave.ts index e76d60c..390af08 100644 --- a/chain/arweave.ts +++ b/chain/arweave.ts @@ -1,5 +1,5 @@ import '../common/eager_offset' -import { Bytes } from '..' +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