OperationService
public class OperationService
Several classes need to use pieces of the forge-sign-parse-preapply-inject flow. This class abstracts those functions away so that it can be shared throughout the library.
-
The configuration object containing all the necessary settings to connect and communicate with the Tezos node
Declaration
Swift
public let config: TezosNodeClientConfig
-
The
NetworkService
object that will perform all the networking callsDeclaration
Swift
public let networkService: NetworkService
-
Init a
TezosNodeClient
with aTezosNodeClientConfig
.Declaration
Swift
public init(config: TezosNodeClientConfig = TezosNodeClientConfig(withDefaultsForNetworkType: .mainnet), networkService: NetworkService)
Parameters
config
A configuration object containing all the necessary settings to connect and communicate with the Tezos node.
-
When using remote forging, every
Operation
needs to be Forged, Parsed, Signed, Preapply’d and Injected to make its way into the blockchain. This function will complete all of those steps and return an OperationID or an Error.Declaration
Swift
public func remoteForgeParseSignPreapplyInject(operationMetadata: OperationMetadata, operationPayload: OperationPayload, wallet: Wallet, completion: @escaping ((Result<String, KukaiError>) -> Void))
Parameters
operationMetadata
The latest
OperationMetadata
from the TezosNodeClientoperationPayload
The
OperationPayload
generated by theOperationFactory
wallet
The
Wallet
that will sign the operationcompletion
Completion block either returning a String containing an OperationHash of the injected Operation, or an Error
-
When using local forging, every
Operation
needs to be Forged, Signed, Preapply’d and Injected to make its way into the blockchain. This function will complete all of those steps and return an OperationID or an Error.Declaration
Swift
public func localForgeSignPreapplyInject(operationMetadata: OperationMetadata, operationPayload: OperationPayload, wallet: Wallet, completion: @escaping ((Result<String, KukaiError>) -> Void))
Parameters
operationMetadata
The latest
OperationMetadata
from the TezosNodeClientoperationPayload
The
OperationPayload
generated by theOperationFactory
wallet
The
Wallet
that will sign the operationcompletion
Completion block either returning a String containing an OperationHash of the injected Operation, or an Error
-
preapplyAndInject(forgedOperation:
signature: signatureCurve: operationPayload: operationMetadata: completion: ) Preapply and Inject wrapped up as one function, for situations like Ledger Wallets, where signing is a complately different process, and must be done elsewhere
Declaration
Swift
public func preapplyAndInject(forgedOperation: String, signature: [UInt8], signatureCurve: EllipticalCurve, operationPayload: OperationPayload, operationMetadata: OperationMetadata, completion: @escaping ((Result<String, KukaiError>) -> Void))
Parameters
forgedOperation
The forged operation hex without a watermark.
signature
Binary representation of the signed operation forge.
signatureCurve
The curve used to sign the forge.
operationPayload
The payload to be sent.
operationMetadata
The metadata required to send the payload.
completion
callback with a forged hash or an error.
-
Forge an
OperationPayload
remotely, so it can be sent to the RPC.Declaration
Swift
public func remoteForge(operationPayload: OperationPayload, completion: @escaping ((Result<String, KukaiError>) -> Void))
Parameters
operationPayload
created from
OperationFactory.operationPayload()
.wallet
The
Wallet
object that will sign the operations.completion
callback with a forged hash or an error.
-
Parse a forged
OperationPayload
on a different server to ensure nobody maliciously tampared with the request.Declaration
Swift
public func remoteParse(forgeResult: Result<String, KukaiError>, operationMetadata: OperationMetadata, operationPayload: OperationPayload, completion: @escaping ((Result<String, KukaiError>) -> Void))
Parameters
forgeResult
The
Result
object from theforge(...)
function.operationMetadata
fetched from
getOperationMetadata(...)
.operationPayload
the
OperationPayload
to compare against to ensure it matches.completion
callback which just returns success or failure with an error.
-
Preapply a signed
OperationPayload
to check for any errors.Declaration
Swift
public func preapply(operationPayload: OperationPayload, completion: @escaping ((Result<[OperationResponse], KukaiError>) -> Void))
Parameters
operationMetadata
Fetched from
getOperationMetadata(...)
.operationPayload
An
OperationPayload
that has had a signature and a protcol added to it.completion
Callback which just returns success or failure with an error.
-
Inject a signed bytes to become part of the next block on the blockchain
Declaration
Swift
public func inject(signedBytes: String, handlePreapplyResult: Result<[OperationResponse], KukaiError>?, completion: @escaping ((Result<String, KukaiError>) -> Void))
Parameters
signedBytes
The result of the forge operation (as a string) with the signature (as a hex string) appended on.
handlePreapplyResult
Optionally pass in the result of the preapply function to reduce the indentation required to perform the full set of operations. Any error will be returned via the injection Result object.