FeeEstimatorService
public class FeeEstimatorService
An object allowing developers to automatically estimate the necessary fee per Operation to ensure it will be accpeted by a Baker. This avoids the need to ask users to enter a fee, which is not a very user friendly approach as most users wouldn’t know what is required.
-
The real signature is not needed for estimation, use the default “Zero Signature” instead
Declaration
Swift
public static let defaultSignature: [UInt8]
-
Declaration
Swift
public static let defaultSignatureHex: String
-
The configuration object containing all the necessary settings to connect and communicate with the Tezos node
Declaration
Swift
public let config: TezosNodeClientConfig
-
The
OperationService
object that will perform forging, parsing, signing, preapply and injections of operationsDeclaration
Swift
public let operationService: OperationService
-
The
NetworkService
that will handle the remote communication.Declaration
Swift
public let networkService: NetworkService
-
Create a FeeEstimatorService that will allow developers to automatically create fees on the users behalf
Declaration
Swift
public init(config: TezosNodeClientConfig = TezosNodeClientConfig(withDefaultsForNetworkType: .mainnet), operationService: OperationService, networkService: NetworkService)
Parameters
operationService
The
OperationService
used to perform the forging.networkService
The
NetworkService
that will handle the remote communication. -
Pass in an array of
Operation
subclasses (useOperationFacotry
to create) to have the library estimate the cost of sending the transaction. Function will use local or remote forging based off config passed in. If the supplied operations contain suggested fees (e.g. from a dApp) this function will estimate the fee and pick which ever is higherDeclaration
Swift
public func estimate(operations: [Operation], operationMetadata: OperationMetadata, constants: NetworkConstants, walletAddress: String, base58EncodedPublicKey: String, completion: @escaping ((Result<EstimationResult, KukaiError>) -> Void))
Parameters
operations
An array of
Operation
subclasses to be estimated.operationMetadata
An
OperationMetadata
object containing necessary info about the current blockchain state.networkConstants
A
NetworkConstants
used to provide information about the current network requirements.withWallet
The
Wallet
object used for signing the transaction.completion
A callback containing the same operations passed in, modified to include fees.
-
Create an array of
OperationFees
from anOperationResponse
.Declaration
Swift
public func extractFees(fromOperationResponse operationResponse: OperationResponse, originalRemoteOps: [Operation], forgedHash: String, withConstants constants: NetworkConstants, fromAddress address: String) -> [OperationFees]
Parameters
fromOperationResponse
The
OperationResponse
resulting from an RPC call to.../run_operation
.forgedHash
The forged hash string resulting from a call to
TezosNodeClient.forge(...)
Return Value
An array of
OperationFees
-
Calculate the fee to add for the given amount of gas
Declaration
Swift
public static func feeForGas(_ gas: Int) -> XTZAmount
-
Calculate the fee to add based on the size of the forged string
Declaration
Swift
public static func feeForStorage(_ forgedHexString: String, numberOfOperations: Int) -> XTZAmount
-
Calculate the fee to add based on how many bytes of storage where needed
Declaration
Swift
public static func feeForBurn(_ burn: Int, withConstants contants: NetworkConstants) -> XTZAmount
-
Declaration
Swift
public static func fee(forGasLimit gasLimit: Int, forgedHexString: String, numberOfOperations: Int) -> XTZAmount
-
Declaration
Swift
public static func addGasSafetyMarginTo(gasUsed: Int) -> Int