-
Notifications
You must be signed in to change notification settings - Fork 12
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 #231 from anoma/improve-gas-estimation
feat: improve gas estimation
- Loading branch information
Showing
20 changed files
with
737 additions
and
77 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,5 @@ | ||
-- This file should undo anything in `up.sql` | ||
DROP TABLE IF EXISTS gas_estimations; | ||
|
||
DROP INDEX IF EXISTS wrapper_transactions_gas; | ||
DROP INDEX IF EXISTS inner_transactions_kind; |
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,26 @@ | ||
-- Your SQL goes here | ||
CREATE TABLE gas_estimations ( | ||
id SERIAL PRIMARY KEY, | ||
wrapper_id VARCHAR(64) NOT NULL, | ||
transparent_transfer INT NOT NULL, | ||
shielded_transfer INT NOT NULL, | ||
shielding_transfer INT NOT NULL, | ||
unshielding_transfer INT NOT NULL, | ||
ibc_msg_transfer INT NOT NULL, | ||
bond INT NOT NULL, | ||
redelegation INT NOT NULL, | ||
unbond INT NOT NULL, | ||
withdraw INT NOT NULL, | ||
claim_rewards INT NOT NULL, | ||
vote_proposal INT NOT NULL, | ||
reveal_pk INT NOT NULL, | ||
tx_size INT NOT NULL, | ||
signatures INT NOT NULL, | ||
CONSTRAINT fk_wrapper_id FOREIGN KEY(wrapper_id) REFERENCES wrapper_transactions(id) ON DELETE CASCADE | ||
); | ||
|
||
ALTER TABLE wrapper_transactions ALTER COLUMN gas_used TYPE INTEGER USING (gas_used::integer) ; | ||
|
||
CREATE INDEX wrapper_transactions_gas ON wrapper_transactions (gas_used); | ||
|
||
CREATE INDEX inner_transactions_kind ON inner_transactions (kind); |
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,7 +1,97 @@ | ||
use crate::balance::Amount; | ||
use crate::id::Id; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct GasPrice { | ||
pub token: String, | ||
pub amount: Amount, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct GasEstimation { | ||
pub wrapper_id: Id, | ||
pub transparent_transfer: u64, | ||
pub shielded_transfer: u64, | ||
pub shielding_transfer: u64, | ||
pub unshielding_transfer: u64, | ||
pub ibc_msg_transfer: u64, | ||
pub bond: u64, | ||
pub redelegation: u64, | ||
pub unbond: u64, | ||
pub withdraw: u64, | ||
pub claim_rewards: u64, | ||
pub vote_proposal: u64, | ||
pub reveal_pk: u64, | ||
pub size: u64, | ||
pub signatures: u64, | ||
} | ||
|
||
impl GasEstimation { | ||
pub fn new(tx_id: Id) -> Self { | ||
Self { | ||
wrapper_id: tx_id, | ||
transparent_transfer: 0, | ||
shielded_transfer: 0, | ||
shielding_transfer: 0, | ||
unshielding_transfer: 0, | ||
ibc_msg_transfer: 0, | ||
bond: 0, | ||
redelegation: 0, | ||
unbond: 0, | ||
withdraw: 0, | ||
claim_rewards: 0, | ||
vote_proposal: 0, | ||
reveal_pk: 0, | ||
size: 0, | ||
signatures: 0, | ||
} | ||
} | ||
|
||
pub fn increase_transparent_transfer(&mut self) { | ||
self.transparent_transfer += 1 | ||
} | ||
|
||
pub fn increase_shielded_transfer(&mut self) { | ||
self.shielded_transfer += 1 | ||
} | ||
|
||
pub fn increase_shielding_transfer(&mut self) { | ||
self.shielding_transfer += 1 | ||
} | ||
|
||
pub fn increase_unshielding_transfer(&mut self) { | ||
self.unshielding_transfer += 1 | ||
} | ||
|
||
pub fn increase_ibc_msg_transfer(&mut self) { | ||
self.ibc_msg_transfer += 1 | ||
} | ||
|
||
pub fn increase_bond(&mut self) { | ||
self.bond += 1 | ||
} | ||
|
||
pub fn increase_redelegation(&mut self) { | ||
self.redelegation += 1 | ||
} | ||
|
||
pub fn increase_unbond(&mut self) { | ||
self.unbond += 1 | ||
} | ||
|
||
pub fn increase_withdraw(&mut self) { | ||
self.withdraw += 1 | ||
} | ||
|
||
pub fn increase_claim_rewards(&mut self) { | ||
self.claim_rewards += 1 | ||
} | ||
|
||
pub fn increase_vote(&mut self) { | ||
self.vote_proposal += 1 | ||
} | ||
|
||
pub fn increase_reveal_pk(&mut self) { | ||
self.reveal_pk += 1 | ||
} | ||
} |
Oops, something went wrong.