-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from algorandfoundation/feat-v11
feat: add stubs for v11 op code and functions
- Loading branch information
Showing
19 changed files
with
899 additions
and
460 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,62 @@ | ||
import { Account, bytes, internal, uint64 } from '@algorandfoundation/algorand-typescript' | ||
import { Account, bytes, internal, Uint64, uint64 } from '@algorandfoundation/algorand-typescript' | ||
import { lazyContext } from '../context-helpers/internal-context' | ||
import { asUint64 } from '../util' | ||
import { itob } from './pure' | ||
import { asUint64, getRandomBytes } from '../util' | ||
|
||
export class BlockData { | ||
seed: bytes | ||
timestamp: uint64 | ||
proposer: Account | ||
feesCollected: uint64 | ||
bonus: uint64 | ||
branch: bytes | ||
feeSink: Account | ||
protocol: bytes | ||
txnCounter: uint64 | ||
proposerPayout: uint64 | ||
|
||
constructor() { | ||
this.seed = getRandomBytes(32).asAlgoTs() | ||
this.timestamp = asUint64(Date.now()) | ||
this.proposer = Account() | ||
this.feesCollected = Uint64(0) | ||
this.bonus = Uint64(0) | ||
this.branch = getRandomBytes(32).asAlgoTs() | ||
this.feeSink = Account() | ||
this.protocol = getRandomBytes(32).asAlgoTs() | ||
this.txnCounter = Uint64(0) | ||
this.proposerPayout = Uint64(0) | ||
} | ||
} | ||
|
||
export const Block: internal.opTypes.BlockType = { | ||
blkSeed: function (a: internal.primitives.StubUint64Compat): bytes { | ||
return itob(lazyContext.ledger.getBlockContent(a).seed) | ||
return lazyContext.ledger.getBlockData(a).seed | ||
}, | ||
blkTimestamp: function (a: internal.primitives.StubUint64Compat): uint64 { | ||
return asUint64(lazyContext.ledger.getBlockContent(a).timestamp) | ||
return lazyContext.ledger.getBlockData(a).timestamp | ||
}, | ||
// TODO: implement v11 methods | ||
blkProposer: function (_a: uint64): Account { | ||
throw new Error('Function not implemented.') | ||
blkProposer: function (a: uint64): Account { | ||
return lazyContext.ledger.getBlockData(a).proposer | ||
}, | ||
blkFeesCollected: function (_a: uint64): uint64 { | ||
throw new Error('Function not implemented.') | ||
blkFeesCollected: function (a: uint64): uint64 { | ||
return lazyContext.ledger.getBlockData(a).feesCollected | ||
}, | ||
blkBonus: function (_a: uint64): uint64 { | ||
throw new Error('Function not implemented.') | ||
blkBonus: function (a: uint64): uint64 { | ||
return lazyContext.ledger.getBlockData(a).bonus | ||
}, | ||
blkBranch: function (_a: uint64): bytes { | ||
throw new Error('Function not implemented.') | ||
blkBranch: function (a: uint64): bytes { | ||
return lazyContext.ledger.getBlockData(a).branch | ||
}, | ||
blkFeeSink: function (_a: uint64): Account { | ||
throw new Error('Function not implemented.') | ||
blkFeeSink: function (a: uint64): Account { | ||
return lazyContext.ledger.getBlockData(a).feeSink | ||
}, | ||
blkProtocol: function (_a: uint64): bytes { | ||
throw new Error('Function not implemented.') | ||
blkProtocol: function (a: uint64): bytes { | ||
return lazyContext.ledger.getBlockData(a).protocol | ||
}, | ||
blkTxnCounter: function (_a: uint64): uint64 { | ||
throw new Error('Function not implemented.') | ||
blkTxnCounter: function (a: uint64): uint64 { | ||
return lazyContext.ledger.getBlockData(a).txnCounter | ||
}, | ||
blkProposerPayout: function (_a: uint64): uint64 { | ||
throw new Error('Function not implemented.') | ||
blkProposerPayout: function (a: uint64): uint64 { | ||
return lazyContext.ledger.getBlockData(a).proposerPayout | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { internal } from '@algorandfoundation/algorand-typescript' | ||
import { lazyContext } from '../context-helpers/internal-context' | ||
|
||
export const onlineStake: internal.opTypes.OnlineStakeType = () => { | ||
return lazyContext.ledger.onlineStake | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Account, internal, uint64 } from '@algorandfoundation/algorand-typescript' | ||
import { lazyContext } from '../context-helpers/internal-context' | ||
import { getAccount } from './acct-params' | ||
|
||
export class VoterData { | ||
balance: uint64 | ||
incentiveEligible: boolean | ||
|
||
constructor() { | ||
this.balance = 0 | ||
this.incentiveEligible = false | ||
} | ||
} | ||
|
||
const getVoterData = (a: Account | internal.primitives.StubUint64Compat): VoterData => { | ||
const acct = getAccount(a) | ||
return lazyContext.getVoterData(acct) | ||
} | ||
|
||
export const VoterParams: internal.opTypes.VoterParamsType = { | ||
voterBalance: function (a: Account | internal.primitives.StubUint64Compat): readonly [uint64, boolean] { | ||
const data = getVoterData(a) | ||
return [data.balance, data.balance !== 0] | ||
}, | ||
voterIncentiveEligible: function (a: Account | internal.primitives.StubUint64Compat): readonly [boolean, boolean] { | ||
const data = getVoterData(a) | ||
return [data.incentiveEligible, data.balance !== 0] | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.