-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: gRPC method to calculate transaction fees
- Loading branch information
1 parent
5abb19a
commit ddecc2a
Showing
14 changed files
with
931 additions
and
2 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
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,42 @@ | ||
import { Arguments } from 'yargs'; | ||
import { CalculateTransactionFeeRequest } from '../../proto/boltzrpc_pb'; | ||
import BuilderComponents, { ApiType, BuilderTypes } from '../BuilderComponents'; | ||
import { callback, loadBoltzClient } from '../Command'; | ||
|
||
export const command = 'txfee <symbol> <transactionId>'; | ||
|
||
export const describe = 'calculate the fee of a transaction'; | ||
|
||
export const builder = { | ||
symbol: BuilderComponents.symbol, | ||
transactionId: { | ||
type: 'string', | ||
describe: 'ID or hash of the transaction', | ||
}, | ||
}; | ||
|
||
export const handler = async ( | ||
argv: Arguments<BuilderTypes<typeof builder> & ApiType>, | ||
) => { | ||
const request = new CalculateTransactionFeeRequest(); | ||
request.setSymbol(argv.symbol); | ||
request.setTransactionId(argv.transactionId); | ||
|
||
loadBoltzClient(argv).calculateTransactionFee( | ||
request, | ||
callback((res) => { | ||
const data: Record<string, number> = { | ||
absolute: res.getAbsolute(), | ||
}; | ||
|
||
if (res.hasSatPerVbyte()) { | ||
data.satPerVbyte = res.getSatPerVbyte(); | ||
} | ||
if (res.hasGwei()) { | ||
data.gwei = res.getGwei(); | ||
} | ||
|
||
return data; | ||
}), | ||
); | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.