-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding in the struct and helper functions for the Ballot Box
- Loading branch information
1 parent
06fa0b2
commit 4f4db15
Showing
25 changed files
with
1,188 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/** | ||
* This code was AUTOGENERATED using the kinobi library. | ||
* Please DO NOT EDIT THIS FILE, instead use visitors | ||
* to add features, then rerun kinobi to update it. | ||
* | ||
* @see https://github.com/kinobi-so/kinobi | ||
*/ | ||
|
||
import { | ||
assertAccountExists, | ||
assertAccountsExist, | ||
combineCodec, | ||
decodeAccount, | ||
fetchEncodedAccount, | ||
fetchEncodedAccounts, | ||
getAddressDecoder, | ||
getAddressEncoder, | ||
getArrayDecoder, | ||
getArrayEncoder, | ||
getStructDecoder, | ||
getStructEncoder, | ||
getU64Decoder, | ||
getU64Encoder, | ||
getU8Decoder, | ||
getU8Encoder, | ||
type Account, | ||
type Address, | ||
type Codec, | ||
type Decoder, | ||
type EncodedAccount, | ||
type Encoder, | ||
type FetchAccountConfig, | ||
type FetchAccountsConfig, | ||
type MaybeAccount, | ||
type MaybeEncodedAccount, | ||
} from '@solana/web3.js'; | ||
import { | ||
getBallotDecoder, | ||
getBallotEncoder, | ||
getBallotTallyDecoder, | ||
getBallotTallyEncoder, | ||
getOperatorVoteDecoder, | ||
getOperatorVoteEncoder, | ||
type Ballot, | ||
type BallotArgs, | ||
type BallotTally, | ||
type BallotTallyArgs, | ||
type OperatorVote, | ||
type OperatorVoteArgs, | ||
} from '../types'; | ||
|
||
export type BallotBox = { | ||
discriminator: bigint; | ||
ncn: Address; | ||
ncnEpoch: bigint; | ||
bump: number; | ||
slotCreated: bigint; | ||
slotConsensusReached: bigint; | ||
reserved: Array<number>; | ||
operatorsVoted: bigint; | ||
uniqueBallots: bigint; | ||
winningBallot: Ballot; | ||
operatorVotes: Array<OperatorVote>; | ||
ballotTallies: Array<BallotTally>; | ||
}; | ||
|
||
export type BallotBoxArgs = { | ||
discriminator: number | bigint; | ||
ncn: Address; | ||
ncnEpoch: number | bigint; | ||
bump: number; | ||
slotCreated: number | bigint; | ||
slotConsensusReached: number | bigint; | ||
reserved: Array<number>; | ||
operatorsVoted: number | bigint; | ||
uniqueBallots: number | bigint; | ||
winningBallot: BallotArgs; | ||
operatorVotes: Array<OperatorVoteArgs>; | ||
ballotTallies: Array<BallotTallyArgs>; | ||
}; | ||
|
||
export function getBallotBoxEncoder(): Encoder<BallotBoxArgs> { | ||
return getStructEncoder([ | ||
['discriminator', getU64Encoder()], | ||
['ncn', getAddressEncoder()], | ||
['ncnEpoch', getU64Encoder()], | ||
['bump', getU8Encoder()], | ||
['slotCreated', getU64Encoder()], | ||
['slotConsensusReached', getU64Encoder()], | ||
['reserved', getArrayEncoder(getU8Encoder(), { size: 128 })], | ||
['operatorsVoted', getU64Encoder()], | ||
['uniqueBallots', getU64Encoder()], | ||
['winningBallot', getBallotEncoder()], | ||
['operatorVotes', getArrayEncoder(getOperatorVoteEncoder(), { size: 32 })], | ||
['ballotTallies', getArrayEncoder(getBallotTallyEncoder(), { size: 32 })], | ||
]); | ||
} | ||
|
||
export function getBallotBoxDecoder(): Decoder<BallotBox> { | ||
return getStructDecoder([ | ||
['discriminator', getU64Decoder()], | ||
['ncn', getAddressDecoder()], | ||
['ncnEpoch', getU64Decoder()], | ||
['bump', getU8Decoder()], | ||
['slotCreated', getU64Decoder()], | ||
['slotConsensusReached', getU64Decoder()], | ||
['reserved', getArrayDecoder(getU8Decoder(), { size: 128 })], | ||
['operatorsVoted', getU64Decoder()], | ||
['uniqueBallots', getU64Decoder()], | ||
['winningBallot', getBallotDecoder()], | ||
['operatorVotes', getArrayDecoder(getOperatorVoteDecoder(), { size: 32 })], | ||
['ballotTallies', getArrayDecoder(getBallotTallyDecoder(), { size: 32 })], | ||
]); | ||
} | ||
|
||
export function getBallotBoxCodec(): Codec<BallotBoxArgs, BallotBox> { | ||
return combineCodec(getBallotBoxEncoder(), getBallotBoxDecoder()); | ||
} | ||
|
||
export function decodeBallotBox<TAddress extends string = string>( | ||
encodedAccount: EncodedAccount<TAddress> | ||
): Account<BallotBox, TAddress>; | ||
export function decodeBallotBox<TAddress extends string = string>( | ||
encodedAccount: MaybeEncodedAccount<TAddress> | ||
): MaybeAccount<BallotBox, TAddress>; | ||
export function decodeBallotBox<TAddress extends string = string>( | ||
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress> | ||
): Account<BallotBox, TAddress> | MaybeAccount<BallotBox, TAddress> { | ||
return decodeAccount( | ||
encodedAccount as MaybeEncodedAccount<TAddress>, | ||
getBallotBoxDecoder() | ||
); | ||
} | ||
|
||
export async function fetchBallotBox<TAddress extends string = string>( | ||
rpc: Parameters<typeof fetchEncodedAccount>[0], | ||
address: Address<TAddress>, | ||
config?: FetchAccountConfig | ||
): Promise<Account<BallotBox, TAddress>> { | ||
const maybeAccount = await fetchMaybeBallotBox(rpc, address, config); | ||
assertAccountExists(maybeAccount); | ||
return maybeAccount; | ||
} | ||
|
||
export async function fetchMaybeBallotBox<TAddress extends string = string>( | ||
rpc: Parameters<typeof fetchEncodedAccount>[0], | ||
address: Address<TAddress>, | ||
config?: FetchAccountConfig | ||
): Promise<MaybeAccount<BallotBox, TAddress>> { | ||
const maybeAccount = await fetchEncodedAccount(rpc, address, config); | ||
return decodeBallotBox(maybeAccount); | ||
} | ||
|
||
export async function fetchAllBallotBox( | ||
rpc: Parameters<typeof fetchEncodedAccounts>[0], | ||
addresses: Array<Address>, | ||
config?: FetchAccountsConfig | ||
): Promise<Account<BallotBox>[]> { | ||
const maybeAccounts = await fetchAllMaybeBallotBox(rpc, addresses, config); | ||
assertAccountsExist(maybeAccounts); | ||
return maybeAccounts; | ||
} | ||
|
||
export async function fetchAllMaybeBallotBox( | ||
rpc: Parameters<typeof fetchEncodedAccounts>[0], | ||
addresses: Array<Address>, | ||
config?: FetchAccountsConfig | ||
): Promise<MaybeAccount<BallotBox>[]> { | ||
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); | ||
return maybeAccounts.map((maybeAccount) => decodeBallotBox(maybeAccount)); | ||
} |
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
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,46 @@ | ||
/** | ||
* This code was AUTOGENERATED using the kinobi library. | ||
* Please DO NOT EDIT THIS FILE, instead use visitors | ||
* to add features, then rerun kinobi to update it. | ||
* | ||
* @see https://github.com/kinobi-so/kinobi | ||
*/ | ||
|
||
import { | ||
combineCodec, | ||
fixDecoderSize, | ||
fixEncoderSize, | ||
getBytesDecoder, | ||
getBytesEncoder, | ||
getStructDecoder, | ||
getStructEncoder, | ||
type Codec, | ||
type Decoder, | ||
type Encoder, | ||
type ReadonlyUint8Array, | ||
} from '@solana/web3.js'; | ||
|
||
export type Ballot = { | ||
merkleRoot: ReadonlyUint8Array; | ||
reserved: ReadonlyUint8Array; | ||
}; | ||
|
||
export type BallotArgs = Ballot; | ||
|
||
export function getBallotEncoder(): Encoder<BallotArgs> { | ||
return getStructEncoder([ | ||
['merkleRoot', fixEncoderSize(getBytesEncoder(), 32)], | ||
['reserved', fixEncoderSize(getBytesEncoder(), 64)], | ||
]); | ||
} | ||
|
||
export function getBallotDecoder(): Decoder<Ballot> { | ||
return getStructDecoder([ | ||
['merkleRoot', fixDecoderSize(getBytesDecoder(), 32)], | ||
['reserved', fixDecoderSize(getBytesDecoder(), 64)], | ||
]); | ||
} | ||
|
||
export function getBallotCodec(): Codec<BallotArgs, Ballot> { | ||
return combineCodec(getBallotEncoder(), getBallotDecoder()); | ||
} |
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,67 @@ | ||
/** | ||
* This code was AUTOGENERATED using the kinobi library. | ||
* Please DO NOT EDIT THIS FILE, instead use visitors | ||
* to add features, then rerun kinobi to update it. | ||
* | ||
* @see https://github.com/kinobi-so/kinobi | ||
*/ | ||
|
||
import { | ||
combineCodec, | ||
fixDecoderSize, | ||
fixEncoderSize, | ||
getBytesDecoder, | ||
getBytesEncoder, | ||
getStructDecoder, | ||
getStructEncoder, | ||
getU128Decoder, | ||
getU128Encoder, | ||
getU64Decoder, | ||
getU64Encoder, | ||
type Codec, | ||
type Decoder, | ||
type Encoder, | ||
type ReadonlyUint8Array, | ||
} from '@solana/web3.js'; | ||
import { | ||
getBallotDecoder, | ||
getBallotEncoder, | ||
type Ballot, | ||
type BallotArgs, | ||
} from '.'; | ||
|
||
export type BallotTally = { | ||
ballot: Ballot; | ||
stakeWeight: bigint; | ||
tally: bigint; | ||
reserved: ReadonlyUint8Array; | ||
}; | ||
|
||
export type BallotTallyArgs = { | ||
ballot: BallotArgs; | ||
stakeWeight: number | bigint; | ||
tally: number | bigint; | ||
reserved: ReadonlyUint8Array; | ||
}; | ||
|
||
export function getBallotTallyEncoder(): Encoder<BallotTallyArgs> { | ||
return getStructEncoder([ | ||
['ballot', getBallotEncoder()], | ||
['stakeWeight', getU128Encoder()], | ||
['tally', getU64Encoder()], | ||
['reserved', fixEncoderSize(getBytesEncoder(), 64)], | ||
]); | ||
} | ||
|
||
export function getBallotTallyDecoder(): Decoder<BallotTally> { | ||
return getStructDecoder([ | ||
['ballot', getBallotDecoder()], | ||
['stakeWeight', getU128Decoder()], | ||
['tally', getU64Decoder()], | ||
['reserved', fixDecoderSize(getBytesDecoder(), 64)], | ||
]); | ||
} | ||
|
||
export function getBallotTallyCodec(): Codec<BallotTallyArgs, BallotTally> { | ||
return combineCodec(getBallotTallyEncoder(), getBallotTallyDecoder()); | ||
} |
Oops, something went wrong.