Skip to content

Commit

Permalink
update proto to have each oneof be u128
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed May 10, 2024
1 parent 843966f commit 8493ed7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 50 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 25 additions & 29 deletions crates/astria-core/src/protocol/transaction/v1alpha1/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,25 +1316,26 @@ impl FeeChangeAction {
raw::FeeChangeAction {
value: Some(match self.fee_change {
FeeChange::TransferBaseFee => {
raw::fee_change_action::Value::TransferBaseFee(vec![])
raw::fee_change_action::Value::TransferBaseFee(self.new_value.into())
}
FeeChange::SequenceBaseFee => {
raw::fee_change_action::Value::SequenceBaseFee(vec![])
raw::fee_change_action::Value::SequenceBaseFee(self.new_value.into())
}
FeeChange::SequenceByteCostMultiplier => {
raw::fee_change_action::Value::SequenceByteCostMultiplier(vec![])
raw::fee_change_action::Value::SequenceByteCostMultiplier(self.new_value.into())
}
FeeChange::InitBridgeAccountBaseFee => {
raw::fee_change_action::Value::InitBridgeAccountBaseFee(vec![])
raw::fee_change_action::Value::InitBridgeAccountBaseFee(self.new_value.into())
}
FeeChange::BridgeLockByteCostMultiplier => {
raw::fee_change_action::Value::BridgeLockByteCostMultiplier(vec![])
raw::fee_change_action::Value::BridgeLockByteCostMultiplier(
self.new_value.into(),
)
}
FeeChange::Ics20WithdrawalBaseFee => {
raw::fee_change_action::Value::Ics20WithdrawalBaseFee(vec![])
raw::fee_change_action::Value::Ics20WithdrawalBaseFee(self.new_value.into())
}
}),
new_value: Some(self.new_value.into()),
}
}

Expand All @@ -1345,30 +1346,31 @@ impl FeeChangeAction {
/// - if the fee change `value` field is missing
/// - if the `new_value` field is missing
pub fn try_from_raw(proto: &raw::FeeChangeAction) -> Result<Self, FeeChangeActionError> {
let fee_change = match proto.value {
Some(raw::fee_change_action::Value::TransferBaseFee(_)) => FeeChange::TransferBaseFee,
Some(raw::fee_change_action::Value::SequenceBaseFee(_)) => FeeChange::SequenceBaseFee,
Some(raw::fee_change_action::Value::SequenceByteCostMultiplier(_)) => {
FeeChange::SequenceByteCostMultiplier
let (fee_change, new_value) = match proto.value {
Some(raw::fee_change_action::Value::TransferBaseFee(new_value)) => {
(FeeChange::TransferBaseFee, new_value)
}
Some(raw::fee_change_action::Value::InitBridgeAccountBaseFee(_)) => {
FeeChange::InitBridgeAccountBaseFee
Some(raw::fee_change_action::Value::SequenceBaseFee(new_value)) => {
(FeeChange::SequenceBaseFee, new_value)
}
Some(raw::fee_change_action::Value::BridgeLockByteCostMultiplier(_)) => {
FeeChange::BridgeLockByteCostMultiplier
Some(raw::fee_change_action::Value::SequenceByteCostMultiplier(new_value)) => {
(FeeChange::SequenceByteCostMultiplier, new_value)
}
Some(raw::fee_change_action::Value::Ics20WithdrawalBaseFee(_)) => {
FeeChange::Ics20WithdrawalBaseFee
Some(raw::fee_change_action::Value::InitBridgeAccountBaseFee(new_value)) => {
(FeeChange::InitBridgeAccountBaseFee, new_value)
}
Some(raw::fee_change_action::Value::BridgeLockByteCostMultiplier(new_value)) => {
(FeeChange::BridgeLockByteCostMultiplier, new_value)
}
Some(raw::fee_change_action::Value::Ics20WithdrawalBaseFee(new_value)) => {
(FeeChange::Ics20WithdrawalBaseFee, new_value)
}
None => return Err(FeeChangeActionError::missing_value_to_change()),
};
let new_value = proto
.new_value
.ok_or(FeeChangeActionError::missing_new_value())?
.into();

Ok(Self {
fee_change,
new_value,
new_value: new_value.into(),
})
}
}
Expand All @@ -1381,16 +1383,10 @@ impl FeeChangeActionError {
fn missing_value_to_change() -> Self {
Self(FeeChangeActionErrorKind::MissingValueToChange)
}

fn missing_new_value() -> Self {
Self(FeeChangeActionErrorKind::MissingNewValue)
}
}

#[derive(Debug, thiserror::Error)]
enum FeeChangeActionErrorKind {
#[error("the value which to change was missing")]
MissingValueToChange,
#[error("the new value was missing")]
MissingNewValue,
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,15 @@ message FeeChangeAction {
// this to accomodate both `base_fee` and `byte_cost_multiplier` for each action.
oneof value {
// core protocol fees are defined on 1-20
bytes transfer_base_fee = 1;
bytes sequence_base_fee = 2;
bytes sequence_byte_cost_multiplier = 3;
astria.primitive.v1.Uint128 transfer_base_fee = 1;
astria.primitive.v1.Uint128 sequence_base_fee = 2;
astria.primitive.v1.Uint128 sequence_byte_cost_multiplier = 3;

// bridge fees are defined on 20-39
bytes init_bridge_account_base_fee = 20;
bytes bridge_lock_byte_cost_multiplier = 21;
astria.primitive.v1.Uint128 init_bridge_account_base_fee = 20;
astria.primitive.v1.Uint128 bridge_lock_byte_cost_multiplier = 21;

// ibc fees are defined on 40-59
bytes ics20_withdrawal_base_fee = 40;
astria.primitive.v1.Uint128 ics20_withdrawal_base_fee = 40;
}
astria.primitive.v1.Uint128 new_value = 101;
}

0 comments on commit 8493ed7

Please sign in to comment.