Skip to content

Commit

Permalink
Conway: proposal procedures
Browse files Browse the repository at this point in the history
  • Loading branch information
janmazak committed Nov 3, 2023
1 parent f4a7be6 commit 9d8150d
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/errors/parseError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ export enum ParseErrorReason {
INVALID_GOV_ACTION_ID = 'Invalid governance action id',
INVALID_VOTING_PROCEDURE = 'Invalid voting procedure',
INVALID_VOTE_OPTION = 'Invalid vote',
INVALID_PROPOSAL_PROCEDURES = 'Invalid proposal procedures',
INVALID_PROPOSAL_PROCEDURE = 'Invalid proposal procedure',
INVALID_TREASURY = 'Invalid treasury',
INVALID_DONATION = 'Invalid donation',
// TODO the order of the items in this enum is messed up?

INVALID_TX_CBOR = 'Invalid transaction CBOR',
}
Expand Down
2 changes: 2 additions & 0 deletions src/errors/validationError.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum ValidationErrorReason {
// Unfixable validation errors
UNSUPPORTED_TX_UPDATE = 'The transaction body entry update must not be included',
UNSUPPORTED_TX_PROPOSAL_PROCEDURES = 'The transaction body entry proposal_procedures must not be included',
UNSUPPORTED_CERTIFICATE_GENESIS_KEY_DELEGATION = 'Certificate of type genesis_key_delegation is not supported and must not be included',
UNSUPPORTED_CERTIFICATE_MOVE_INSTANTANEOUS_REWARDS_CERT = 'Certificate of type move_instantaneous_rewards_cert is not supported and must not be included',
UNSUPPORTED_CERTIFICATE_STAKE_VOTE_DELEG = 'Certificate of type stake_vote_deleg_cert is not supported and must not be included',
Expand Down Expand Up @@ -32,6 +33,7 @@ const UNFIXABLE = false

const validationErrorFixability: Record<ValidationErrorReason, boolean> = {
[ValidationErrorReason.UNSUPPORTED_TX_UPDATE]: UNFIXABLE,
[ValidationErrorReason.UNSUPPORTED_TX_PROPOSAL_PROCEDURES]: UNFIXABLE,
[ValidationErrorReason.UNSUPPORTED_CERTIFICATE_GENESIS_KEY_DELEGATION]:
UNFIXABLE,
[ValidationErrorReason.UNSUPPORTED_CERTIFICATE_MOVE_INSTANTANEOUS_REWARDS_CERT]:
Expand Down
29 changes: 29 additions & 0 deletions src/txParsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import {
VotingProcedure,
VoteOption,
Coin,
ProposalProcedure,
} from './types'
import {
BabbageTransactionOutputKeys,
Expand Down Expand Up @@ -960,6 +961,30 @@ const parseVotingProcedures = (unparsed: unknown): Ballot[] => {
}))
}

const parseProposalProcedure = (
unparsedProcedure: unknown,
): ProposalProcedure => {
const [deposit, rewardAccount, govAction, anchor] = parseTuple(
unparsedProcedure,
ParseErrorReason.INVALID_PROPOSAL_PROCEDURE,
parseCoin,
parseRewardAccount,
doNotParse,
parseAnchor, // TODO not nullable, should we check for that?
)
return {
deposit,
rewardAccount,
govAction,
anchor,
}
}
const parseProposalProcedures = createParser(
parseArray,
parseProposalProcedure,
ParseErrorReason.INVALID_PROPOSAL_PROCEDURES,
)

const parseTreasury = createParser(parseUint, ParseErrorReason.INVALID_TREASURY)
const parseDonation = (unparsed: unknown): Coin => {
const coin = parseUint(unparsed, ParseErrorReason.INVALID_DONATION)
Expand Down Expand Up @@ -1037,6 +1062,10 @@ export const parseTxBody = (unparsedTxBody: unknown): TransactionBody => {
unparsedTxBody.get(TransactionBodyKeys.VOTING_PROCEDURES),
parseVotingProcedures,
),
proposalProcedures: parseOptional(
unparsedTxBody.get(TransactionBodyKeys.PROPOSAL_PROCEDURES),
parseProposalProcedures,
),
treasury: parseOptional(
unparsedTxBody.get(TransactionBodyKeys.TREASURY),
parseTreasury,
Expand Down
12 changes: 12 additions & 0 deletions src/txSerializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
Voter,
GovActionId,
VotingProcedure,
ProposalProcedure,
} from './types'
import {
BabbageTransactionOutputKeys,
Expand Down Expand Up @@ -305,6 +306,13 @@ const serializeVotingProcedures = (ballots: Ballot[]) =>
]),
)

const serializeProposalProcedure = (procedure: ProposalProcedure) => [
procedure.deposit,
procedure.rewardAccount,
procedure.govAction,
serializeAnchor(procedure.anchor),
]

export const serializeTxBody = (txBody: TransactionBody) =>
filteredMap<TransactionBodyKeys, unknown>([
[TransactionBodyKeys.INPUTS, txBody.inputs.map(serializeTxInput)],
Expand Down Expand Up @@ -351,6 +359,10 @@ export const serializeTxBody = (txBody: TransactionBody) =>
txBody.votingProcedures &&
serializeVotingProcedures(txBody.votingProcedures),
],
[
TransactionBodyKeys.PROPOSAL_PROCEDURES,
txBody.proposalProcedures?.map(serializeProposalProcedure),
],
[TransactionBodyKeys.TREASURY, identity(txBody.treasury)],
[TransactionBodyKeys.DONATION, identity(txBody.donation)],
])
Expand Down
3 changes: 3 additions & 0 deletions src/txTransformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export const transformTxBody = (
txBody.collateralReturnOutput &&
transformTxOutput(txBody.collateralReturnOutput),
referenceInputs: transformOptionalList(txBody.referenceInputs),
// TODO voting procedures? there might be empty map
// TODO proposal procedures? empty list, and
// check with CDDL which lists are nonempty there, maybe we should check it at parsing immediately
auxiliaryDataHash: transformAuxiliaryDataHash(
txBody.auxiliaryDataHash,
auxiliaryData,
Expand Down
7 changes: 7 additions & 0 deletions src/txValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,13 @@ function* validateTxBody(txBody: TransactionBody): ValidatorReturnType {
bind(validateUint64, 'transaction_body.total_collateral'),
)
yield* validateOptional(txBody.referenceInputs, validateReferenceInputs)
yield* validate(
txBody.proposalProcedures === undefined,
err(
ValidationErrorReason.UNSUPPORTED_TX_PROPOSAL_PROCEDURES,
'transaction_body.proposal_procedures',
),
)
yield* validateOptional(
txBody.treasury,
bind(validateUint64, 'transaction_body.treasury'),
Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ export type Ballot = {
votes: Vote[]
}

export type ProposalProcedure = {
deposit: Coin
rewardAccount: RewardAccount
govAction: Unparsed
anchor: Anchor
}

// Transaction body
export type TransactionBody = {
inputs: TransactionInput[]
Expand All @@ -482,6 +489,7 @@ export type TransactionBody = {
totalCollateral?: Coin
referenceInputs?: TransactionInput[]
votingProcedures?: Ballot[]
proposalProcedures?: ProposalProcedure[]
treasury?: Coin
donation?: Coin
}
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export enum TransactionBodyKeys {
TOTAL_COLLATERAL = 17,
REFERENCE_INPUTS = 18,
VOTING_PROCEDURES = 19,
PROPOSAL_PROCEDURES = 20,
TREASURY = 21,
DONATION = 22,
}
Expand Down
93 changes: 93 additions & 0 deletions test/integration/__fixtures__/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const ValidTransactionBodyTestCases: ValidTransactionBodyTestCase[] = [
totalCollateral: undefined,
referenceInputs: undefined,
votingProcedures: undefined,
proposalProcedures: undefined,
treasury: undefined,
donation: undefined,
},
Expand Down Expand Up @@ -134,6 +135,7 @@ export const ValidTransactionBodyTestCases: ValidTransactionBodyTestCase[] = [
totalCollateral: undefined,
referenceInputs: undefined,
votingProcedures: undefined,
proposalProcedures: undefined,
treasury: undefined,
donation: undefined,
},
Expand Down Expand Up @@ -240,6 +242,7 @@ export const ValidTransactionBodyTestCases: ValidTransactionBodyTestCase[] = [
totalCollateral: undefined,
referenceInputs: undefined,
votingProcedures: undefined,
proposalProcedures: undefined,
treasury: undefined,
donation: undefined,
},
Expand Down Expand Up @@ -388,6 +391,7 @@ export const ValidTransactionBodyTestCases: ValidTransactionBodyTestCase[] = [
totalCollateral: undefined,
referenceInputs: undefined,
votingProcedures: undefined,
proposalProcedures: undefined,
treasury: undefined,
donation: undefined,
},
Expand Down Expand Up @@ -492,6 +496,7 @@ export const ValidTransactionBodyTestCases: ValidTransactionBodyTestCase[] = [
totalCollateral: undefined,
referenceInputs: undefined,
votingProcedures: undefined,
proposalProcedures: undefined,
treasury: undefined,
donation: undefined,
},
Expand Down Expand Up @@ -576,6 +581,7 @@ export const ValidTransactionBodyTestCases: ValidTransactionBodyTestCase[] = [
},
],
votingProcedures: undefined,
proposalProcedures: undefined,
treasury: undefined,
donation: undefined,
},
Expand Down Expand Up @@ -650,6 +656,87 @@ export const ValidTransactionBodyTestCases: ValidTransactionBodyTestCase[] = [
],
},
],
proposalProcedures: undefined,
treasury: undefined,
donation: undefined,
},
},
{
// https://auspicious-fuchsia-2e9.notion.site/Transactions-in-SanchoNet-fbcf91c799404fe4b30a78e8e091df79#a5ef58aa46e84d2f96d0b14f906e0417
testName: 'Conway tx body: proposal procedures',
cbor: 'a40081825820017b91576a79a3602a02a65b600665ab71037ad14aa162538a26e64b3f5069fc000181a2005839002d745f050a8f7e263f4d0749a82284ed9cc065018c1f4f6a7c1b764882293a49e3ef29a4f9c32e4c18f202f5324182db7790f48dccf7a6dd011b0000000253d1efbc021a0002b3b11481841a000f4240581de082293a49e3ef29a4f9c32e4c18f202f5324182db7790f48dccf7a6dd8305f68282781968747470733a2f2f73686f727475726c2e61742f6173494a365820ee90ece16c47bf812b88edb89a01539e6683d6549a80b15383a4fb218ab9412df682781968747470733a2f2f73686f727475726c2e61742f784d53313558206f890de0c6e418e6526e2b1aa821850cb87aee94a6d77dc2a2e440116abc8e09',
txBody: {
inputs: [
{
transactionId: toFixLenBuffer(
'017b91576a79a3602a02a65b600665ab71037ad14aa162538a26e64b3f5069fc',
32,
),
index: toUint(0),
},
],
outputs: [
{
format: TxOutputFormat.MAP_BABBAGE,
address: toFixLenBuffer(
'002d745f050a8f7e263f4d0749a82284ed9cc065018c1f4f6a7c1b764882293a49e3ef29a4f9c32e4c18f202f5324182db7790f48dccf7a6dd',
57,
),
amount: {
type: AmountType.WITHOUT_MULTIASSET,
coin: toUint(9996201916),
},
datum: undefined,
referenceScript: undefined,
},
],
fee: toUint(177073),
ttl: undefined,
certificates: undefined,
withdrawals: undefined,
update: undefined,
auxiliaryDataHash: undefined,
validityIntervalStart: undefined,
mint: undefined,
scriptDataHash: undefined,
collateralInputs: undefined,
requiredSigners: undefined,
networkId: undefined,
collateralReturnOutput: undefined,
totalCollateral: undefined,
referenceInputs: undefined,
votingProcedures: undefined,
proposalProcedures: [
{
deposit: toUint(1000000),
rewardAccount: toFixLenBuffer(
'e082293a49e3ef29a4f9c32e4c18f202f5324182db7790f48dccf7a6dd',
29,
),
govAction: [
5,
null,
[
// constitution
[
'https://shorturl.at/asIJ6',
toFixLenBuffer(
'ee90ece16c47bf812b88edb89a01539e6683d6549a80b15383a4fb218ab9412d',
32,
),
],
null,
],
],
anchor: {
url: toMaxLenString('https://shorturl.at/xMS15', 64),
dataHash: toFixLenBuffer(
'6f890de0c6e418e6526e2b1aa821850cb87aee94a6d77dc2a2e440116abc8e09',
32,
),
},
},
],
treasury: undefined,
donation: undefined,
},
Expand Down Expand Up @@ -708,6 +795,7 @@ export const TransformTransactionTestCases: TransformTransactionBodyTestCase[] =
totalCollateral: undefined,
referenceInputs: undefined,
votingProcedures: undefined,
proposalProcedures: undefined,
treasury: undefined,
donation: undefined,
},
Expand Down Expand Up @@ -755,6 +843,7 @@ export const TransformTransactionTestCases: TransformTransactionBodyTestCase[] =
totalCollateral: undefined,
referenceInputs: undefined,
votingProcedures: undefined,
proposalProcedures: undefined,
treasury: undefined,
donation: undefined,
},
Expand Down Expand Up @@ -805,6 +894,7 @@ export const TransformTransactionTestCases: TransformTransactionBodyTestCase[] =
totalCollateral: undefined,
referenceInputs: undefined,
votingProcedures: undefined,
proposalProcedures: undefined,
treasury: undefined,
donation: undefined,
},
Expand Down Expand Up @@ -861,6 +951,7 @@ export const ValidTransactionTestCases: ValidTransactionTestCase[] = [
totalCollateral: undefined,
referenceInputs: undefined,
votingProcedures: undefined,
proposalProcedures: undefined,
treasury: undefined,
donation: undefined,
},
Expand Down Expand Up @@ -934,6 +1025,7 @@ export const ValidTransactionTestCases: ValidTransactionTestCase[] = [
totalCollateral: undefined,
referenceInputs: undefined,
votingProcedures: undefined,
proposalProcedures: undefined,
treasury: undefined,
donation: undefined,
},
Expand Down Expand Up @@ -1075,6 +1167,7 @@ export const ValidTransactionTestCases: ValidTransactionTestCase[] = [
totalCollateral: undefined,
referenceInputs: undefined,
votingProcedures: undefined,
proposalProcedures: undefined,
treasury: undefined,
donation: undefined,
},
Expand Down

0 comments on commit 9d8150d

Please sign in to comment.