Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web3.js: add Connection.getFeeForMessage #22128

Merged
merged 4 commits into from
Jan 11, 2022

Conversation

fanatid
Copy link
Contributor

@fanatid fanatid commented Dec 27, 2021

Closes #20100

Not sure that we should check the node version before making the request as Rust client do, I think it's ok if the request fails.

pub fn get_fee_for_message(&self, message: &Message) -> ClientResult<u64> {
if self.get_node_version()? < semver::Version::new(1, 9, 0) {
let fee_calculator = self
.get_fee_calculator_for_blockhash(&message.recent_blockhash)?
.ok_or_else(|| ClientErrorKind::Custom("Invalid blockhash".to_string()))?;
Ok(fee_calculator
.lamports_per_signature
.saturating_mul(message.header.num_required_signatures as u64))
} else {
let serialized_encoded =
serialize_and_encode::<Message>(message, UiTransactionEncoding::Base64)?;
let result = self.send::<Response<Option<u64>>>(
RpcRequest::GetFeeForMessage,
json!([serialized_encoded, self.commitment()]),
)?;
result
.value
.ok_or_else(|| ClientErrorKind::Custom("Invalid blockhash".to_string()).into())
}
}

@mergify mergify bot added the community Community contribution label Dec 27, 2021
@mergify mergify bot requested a review from a team December 27, 2021 17:22
@stale
Copy link

stale bot commented Jan 9, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale [bot only] Added to stale content; results in auto-close after a week. label Jan 9, 2022
@codecov
Copy link

codecov bot commented Jan 10, 2022

Codecov Report

Merging #22128 (481eeb9) into master (bb97c8f) will decrease coverage by 11.2%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           master   #22128       +/-   ##
===========================================
- Coverage    81.2%    70.0%    -11.3%     
===========================================
  Files         519       35      -484     
  Lines      145754     2093   -143661     
  Branches        0      301      +301     
===========================================
- Hits       118466     1466   -117000     
+ Misses      27288      523    -26765     
- Partials        0      104      +104     

web3.js/src/connection.ts Outdated Show resolved Hide resolved
@stale stale bot removed the stale [bot only] Added to stale content; results in auto-close after a week. label Jan 10, 2022
web3.js/src/connection.ts Outdated Show resolved Hide resolved
web3.js/src/connection.ts Outdated Show resolved Hide resolved
@mergify mergify bot dismissed jstarry’s stale review January 11, 2022 09:06

Pull request has been modified.

@fanatid
Copy link
Contributor Author

fanatid commented Jan 11, 2022

@jstarry thanks again 👍 these were stupid mistakes from me 🤦‍♂️

@jstarry
Copy link
Member

jstarry commented Jan 11, 2022

@jstarry thanks again 👍 these were stupid mistakes from me 🤦‍♂️

no problem, thank you for the contribution!

@jstarry jstarry merged commit 3c44d40 into solana-labs:master Jan 11, 2022
@fanatid fanatid deleted the web3js-get-fee-for-message branch January 11, 2022 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

web3: implement get_fee_for_message
2 participants