|
1 | | -import { Account, bytes, internal, uint64 } from '@algorandfoundation/algorand-typescript' |
| 1 | +import { Account, bytes, internal, Uint64, uint64 } from '@algorandfoundation/algorand-typescript' |
2 | 2 | import { lazyContext } from '../context-helpers/internal-context' |
3 | | -import { asUint64 } from '../util' |
4 | | -import { itob } from './pure' |
| 3 | +import { asUint64, getRandomBytes } from '../util' |
| 4 | + |
| 5 | +export class BlockData { |
| 6 | + seed: bytes |
| 7 | + timestamp: uint64 |
| 8 | + proposer: Account |
| 9 | + feesCollected: uint64 |
| 10 | + bonus: uint64 |
| 11 | + branch: bytes |
| 12 | + feeSink: Account |
| 13 | + protocol: bytes |
| 14 | + txnCounter: uint64 |
| 15 | + proposerPayout: uint64 |
| 16 | + |
| 17 | + constructor() { |
| 18 | + this.seed = getRandomBytes(32).asAlgoTs() |
| 19 | + this.timestamp = asUint64(Date.now()) |
| 20 | + this.proposer = Account() |
| 21 | + this.feesCollected = Uint64(0) |
| 22 | + this.bonus = Uint64(0) |
| 23 | + this.branch = getRandomBytes(32).asAlgoTs() |
| 24 | + this.feeSink = Account() |
| 25 | + this.protocol = getRandomBytes(32).asAlgoTs() |
| 26 | + this.txnCounter = Uint64(0) |
| 27 | + this.proposerPayout = Uint64(0) |
| 28 | + } |
| 29 | +} |
5 | 30 |
|
6 | 31 | export const Block: internal.opTypes.BlockType = { |
7 | 32 | blkSeed: function (a: internal.primitives.StubUint64Compat): bytes { |
8 | | - return itob(lazyContext.ledger.getBlockContent(a).seed) |
| 33 | + return lazyContext.ledger.getBlockData(a).seed |
9 | 34 | }, |
10 | 35 | blkTimestamp: function (a: internal.primitives.StubUint64Compat): uint64 { |
11 | | - return asUint64(lazyContext.ledger.getBlockContent(a).timestamp) |
| 36 | + return lazyContext.ledger.getBlockData(a).timestamp |
12 | 37 | }, |
13 | | - // TODO: implement v11 methods |
14 | | - blkProposer: function (_a: uint64): Account { |
15 | | - throw new Error('Function not implemented.') |
| 38 | + blkProposer: function (a: uint64): Account { |
| 39 | + return lazyContext.ledger.getBlockData(a).proposer |
16 | 40 | }, |
17 | | - blkFeesCollected: function (_a: uint64): uint64 { |
18 | | - throw new Error('Function not implemented.') |
| 41 | + blkFeesCollected: function (a: uint64): uint64 { |
| 42 | + return lazyContext.ledger.getBlockData(a).feesCollected |
19 | 43 | }, |
20 | | - blkBonus: function (_a: uint64): uint64 { |
21 | | - throw new Error('Function not implemented.') |
| 44 | + blkBonus: function (a: uint64): uint64 { |
| 45 | + return lazyContext.ledger.getBlockData(a).bonus |
22 | 46 | }, |
23 | | - blkBranch: function (_a: uint64): bytes { |
24 | | - throw new Error('Function not implemented.') |
| 47 | + blkBranch: function (a: uint64): bytes { |
| 48 | + return lazyContext.ledger.getBlockData(a).branch |
25 | 49 | }, |
26 | | - blkFeeSink: function (_a: uint64): Account { |
27 | | - throw new Error('Function not implemented.') |
| 50 | + blkFeeSink: function (a: uint64): Account { |
| 51 | + return lazyContext.ledger.getBlockData(a).feeSink |
28 | 52 | }, |
29 | | - blkProtocol: function (_a: uint64): bytes { |
30 | | - throw new Error('Function not implemented.') |
| 53 | + blkProtocol: function (a: uint64): bytes { |
| 54 | + return lazyContext.ledger.getBlockData(a).protocol |
31 | 55 | }, |
32 | | - blkTxnCounter: function (_a: uint64): uint64 { |
33 | | - throw new Error('Function not implemented.') |
| 56 | + blkTxnCounter: function (a: uint64): uint64 { |
| 57 | + return lazyContext.ledger.getBlockData(a).txnCounter |
34 | 58 | }, |
35 | | - blkProposerPayout: function (_a: uint64): uint64 { |
36 | | - throw new Error('Function not implemented.') |
| 59 | + blkProposerPayout: function (a: uint64): uint64 { |
| 60 | + return lazyContext.ledger.getBlockData(a).proposerPayout |
37 | 61 | }, |
38 | 62 | } |
0 commit comments