EosioTransaction
public class EosioTransaction : Codable
Class for creating, preparing, signing, and (optionally) broadcasting transactions on EOSIO-based blockchains.
-
Chain ID in
String
format.Declaration
Swift
public var chainId: String
-
Remote Procedure Call (RPC) provider for facilitating communication with blockchain nodes. Conforms to
EosioRpcProviderProtocol
.Declaration
Swift
public var rpcProvider: EosioRpcProviderProtocol?
-
Application Binary Interface (ABI) provider for facilitating the fetching and caching of ABIs from blockchain nodes. A default is provided. Conforms to
EosioAbiProviderProtocol
.Declaration
Swift
public var abiProvider: EosioAbiProviderProtocol?
-
Signature provider for facilitating the retrieval of available public keys and the signing of transactions. Conforms to
EosioSignatureProviderProtocol
.Declaration
Swift
public var signatureProvider: EosioSignatureProviderProtocol?
-
Serialization provider for facilitating ABI-driven transaction and action (de)serialization between JSON and binary data representations. Conforms to
EosioSerializationProviderProtocol
.Declaration
Swift
public var serializationProvider: EosioSerializationProviderProtocol? { get set }
-
Transaction configuration.
Declaration
Swift
public var config: EosioTransaction.Config
-
Struct defining relative transaction configuration options and defaults.
See moreDeclaration
Swift
public struct Config
-
Should signature providers be permitted to modify the transaction prior to signing? Defaults to
true
.Declaration
Swift
public var allowSignatureProviderToModifyTransaction: Bool
-
Manager of ABIs for actions in the transaction.
Declaration
Swift
public let abis: EosioTransaction.Abis
-
Transaction property: Time at which the transaction expires and can no longer be included in a block.
Declaration
Swift
public var expiration: Date
-
Transaction property: Reference block number. Helps prevent replay attacks.
Declaration
Swift
public var refBlockNum: UInt16
-
Transaction property: Reference block prefix. Helps prevent replay attacks.
Declaration
Swift
public var refBlockPrefix: UInt64
-
Transaction property: Network bandwidth billing limit.
Declaration
Swift
public var maxNetUsageWords: UInt
-
Transaction property: CPU time billing limit, in milliseconds.
Declaration
Swift
public var maxCpuUsageMs: UInt
-
Transaction property: Causes the transaction to be executed a specified number of seconds after being included in a block. It may be canceled during this delay.
Declaration
Swift
public var delaySec: UInt
-
Transaction property: Array of actions to be executed.
Declaration
Swift
public private(set) var actions: [EosioTransaction.Action] { get }
-
Transaction property: Context Free Actions.
Declaration
Swift
public private(set) var contextFreeActions: [EosioTransaction.Action] { get }
-
Context free data
Declaration
Swift
public var contextFreeData: [Data]
-
Serialized Context free data
Declaration
Swift
public private(set) var serializedContextFreeData: Data { get }
-
Transaction property: Transaction Extensions.
Declaration
Swift
public var transactionExtensions: [String]
-
Transaction data serialized into a binary representation in preparation for broadcast.
Declaration
Swift
public private(set) var serializedTransaction: Data? { get }
-
Array of signatures.
Declaration
Swift
public private(set) var signatures: [String]? { get }
-
Transaction ID.
Declaration
Swift
public private(set) var transactionId: String? { get }
-
Add an Action.
Declaration
Swift
public func add(action: Action, at: Int? = nil)
Parameters
action
The Action to add.
at
An optional index at which to insert the Action. If not provided, the Action will be appended to the end of the actions array.
-
Add an array of Actions.
Declaration
Swift
public func add(actions: [Action])
Parameters
actions
The array of Actions to append.
-
Add a context free Action.
Declaration
Swift
public func add(contextFreeAction: Action, at: Int? = nil)
Parameters
contextFreeAction
The context free Action to add.
at
An optional index at which to insert the context free Action. If not provided, the Action will be appended to the end of the contextFreeActions array.
-
Add an array of context free Actions.
Declaration
Swift
public func add(contextFreeActions: [Action])
Parameters
contextFreeActions
The array of context free Actions to append.
-
Initializes the class.
Declaration
Swift
public init()
-
Deserialize a serialized transaction and return an
EosioTransaction
object.Throws
If the transaction cannot be deserialized.Declaration
Swift
public static func deserialize(_ serializedTransaction: Data, serializationProvider: EosioSerializationProviderProtocol) throws -> EosioTransaction
Parameters
serializedTransaction
A serialized transaction as Data.
serializationProvider
A serialization provider. Will be used for transaction deserialization and set as the
serializationProvider
on the returnedEosioTransaction
.Return Value
An
EosioTransaction
. -
Serialize context free data
Declaration
Swift
public static func serialize(contextFreeData: [Data]) -> Data
Parameters
contextFreeData
array of context free data
Return Value
The serialized context free data
-
Returns an array of unserialized actions.
Declaration
Swift
public var actionsWithoutSerializedData: [Action] { get }
-
Return this transaction as a json string with unserialized action data
Declaration
Swift
public var transactionAsJsonWithUnserializedActionData: String? { get }
-
Return this transaction as a Dictionary. Action data will be unserialized.
Declaration
Swift
public var transactionAsDictionary: [String : Any] { get }
-
Encode the transaction as a json string. Properties will be snake_case. Action data will be serialized.
Throws
If the transaction cannot be encoded to json.Declaration
Swift
public func toJson(prettyPrinted: Bool = false) throws -> String
Parameters
prettyPrinted
Should the json be pretty printed? (default = false)
Return Value
The transaction as a json string.
-
Serializes the transaction and returns a
Data
object. Serializing a transaction requires theserializedData
property for all the actions to have a value and the TAPOS properties (refBlockNum
,refBlockPrefix
,expiration
) to have valid values. If the necessary data is not known to be set, call the asynchronous version of this method, which will attempt to get the necessary data first.Throws
If any of the necessary data is missing or transaction cannot be serialized.Declaration
Swift
public func serializeTransaction() throws -> Data
Return Value
A
Data
object representing the serialized transaction. -
Asynchronous version of serializeTransaction that calls
prepare(completion:)
before attemping to create a serialized transaction. If an error is encountered, this method will call the completion with that error. Otherwise, the completion will be called with a serialized transaction.Declaration
Swift
public func serializeTransaction(completion: @escaping (EosioResult<Data, EosioError>) -> Void)
Parameters
completion
Called with an
EosioResult
consisting ofData
for success and an optionalEosioError
. -
Prepares the transaction, fetching or calculating any needed values by calling
calculateExpiration()
,getChainIdAndCalculateTapos(completion:)
, andserializeActionData(completion:)
. If any of these methods returns an error, this method will call the completion with that error.Declaration
Swift
public func prepare(completion: @escaping (EosioResult<Bool, EosioError>) -> Void)
Parameters
completion
Called with an
EosioResult
consisting of aBool
for success and an optionalEosioError
. -
Serializes the
data
property of each action inactions
and sets theserializedData
property for each action, if not already set. Serializing the action data requires ABIs to be available in theabis
class for all the contracts in the actions. If the necessary ABIs are not known to be available, call the asynchronous version of this method, which will attempt to get the ABIs first.Throws
If any required abis are not available, or the actiondata
cannot be serialized.Declaration
Swift
public func serializeActionData() throws
-
Calls
getABIs(completion:)
before attemping to serialize the actions data by callingserializeActionData()
. IfgetABIs(completion:)
returns an error, this method will call the completion with that error. IfserializeActionData()
throws an error, the completion will be called with that error. If all action data is successfully serialized, the completion will be called withtrue
.Declaration
Swift
public func serializeActionData(completion: @escaping (EosioResult<Bool, EosioError>) -> Void)
Parameters
completion
Called with an
EosioResult
consisting of aBool
for success and an optionalEosioError
. -
Deserializes the
serializedData
property of each action inactions
and sets thedata
property for each action, if not already set. Deserializing the action data requires an ABI to be available in theabis
class for the action.Throws
If any required abis are not available, or the action data cannot be deserialized.Declaration
Swift
public func deserializeActionData(exclude: [EosioName] = []) throws
Parameters
exclude
Don’t deserialize these actions.
-
Gets ABIs for every contract in the actions using the
abiProvider
and adds them toabis
. If ABIs are already present for all contracts, this method will not need to use theabiProvider
and will immediately call the completion withtrue
. If theabiProvider
is not set but therpcProvider
is, anEosioAbiProvider
instance will be created using therpcProvider
and set as theabiProvider
. If the ABIs are not present and theabiProvider
is not set orabiProvider
cannot get some of the requested ABIs, an error is returned. If all ABIs are successfully set, this method will call the completion withtrue
.Declaration
Swift
public func getAbis(completion: @escaping (EosioResult<Bool, EosioError>) -> Void)
Parameters
completion
Called with an
EosioResult
consisting of aBool
for success and an optionalEosioError
. -
Gets the block specified by
blockNum
and setsrefBlockNum
andrefBlockPrefix
. IfrefBlockNum
andrefBlockPrefix
already have valid values, this method will call the completion withtrue
. If these properties do not have valid values, this method will require anrpcProvider
to get the data for these values. If therpcProvider
is not set or another error is encountered, this method will call the completion with an error.Declaration
Swift
public func getBlockAndSetTapos(blockNum: UInt64, completion: @escaping (EosioResult<Bool, EosioError>) -> Void)
Parameters
blockNum
The block number serving as the basis for TAPOS calculations.
completion
Called with an
EosioResult
consisting of aBool
for success and an optionalEosioError
. -
Signs a transaction by getting the available keys from the
signatureProvider
and callingsign(availableKeys:, completion:)
.Declaration
Swift
public func sign(prompt: String = "Sign Transaction", completion: @escaping (EosioResult<Bool, EosioError>) -> Void)
-
Signs a transaction by preparing the transaction and calling
signPreparedTransaction(availableKeys:, completion:)
.Declaration
Swift
public func sign(availableKeys: [String], prompt: String = "Sign Transaction", completion: @escaping (EosioResult<Bool, EosioError>) -> Void)
Parameters
availableKeys
An array of public key strings that correspond to the private keys availble for signing.
prompt
Prompt to present with biometrics authentication, if required.
completion
Called with an
EosioResult
consisting of aBool
for success and an optionalEosioError
. -
Serializes the transaction and then signs with the private keys corresponding to the passed-in public keys. If successful, sets the
signatures
and returnstrue
. Otherwise returns an error.Declaration
Swift
public func sign(publicKeys: [String], prompt: String = "Sign Transaction", completion: @escaping (EosioResult<Bool, EosioError>) -> Void)
Parameters
publicKeys
An array of public key strings that correspond to the private keys to sign the transaction with.
prompt
Prompt to present with biometric authentication if required.
completion
Called with an
EosioResult
consisting of aBool
for success and an optionalEosioError
. -
Broadcasts a signed transaction. If successful, sets the
transactionId
and returnstrue
. Otherwise returns an error.Declaration
Swift
public func broadcast(completion: @escaping (EosioResult<Bool, EosioError>) -> Void)
Parameters
completion
Called with an
EosioResult
consisting of aBool
for success and an optionalEosioError
. -
Signs a transaction and then broadcasts it.
Declaration
Swift
public func signAndBroadcast(completion: @escaping (EosioResult<Bool, EosioError>) -> Void)
Parameters
completion
Called with an
EosioResult
consisting of aBool
for success and an optionalEosioError
. -
Manages Application Binary Interfaces (ABIs) associated with an
See moreEosioTransaction
instance.Declaration
Swift
class Abis
-
Action class for
See moreEosioTransaction
Declaration
Swift
class Action : Codable
-
Publisher based method for signing a transaction and then broadcasting it.
Returns an AnyPublisher
. Declaration
Swift
public func signAndBroadcastPublisher() -> AnyPublisher<Bool, EosioError>
-
Publisher based method for signing a transaction.
Returns AnyPublisher
. Declaration
Swift
public func signPublisher() -> AnyPublisher<Bool, EosioError>
-
Publisher based method for signing a transaction with available keys.
Returns AnyPublisher
. Declaration
Swift
public func signPublisher(availableKeys: [String]) -> AnyPublisher<Bool, EosioError>
Parameters
availableKeys
An array of public key strings that correspond to the private keys availble for signing.
-
Publisher based method for signing a transaction with publicKeys keys.
Returns AnyPublisher
. Declaration
Swift
public func signPublisher(publicKeys: [String]) -> AnyPublisher<Bool, EosioError>
Parameters
publicKeys
An array of public key strings that correspond to the private keys to sign the transaction with.
-
Publisher based method for broadcast a transaction.
Returns Promise
. Declaration
Swift
public func broadcastPublisher() -> AnyPublisher<Bool, EosioError>
-
Publisher based method to serialize a transaction.
Returns AnyPublisher.
Declaration
Swift
public func serializeTransactionPublisher() -> AnyPublisher<Data, EosioError>
-
Publisher based method to prepare a transaction.
Returns AnyPublisher
. Declaration
Swift
public func preparePublisher() -> AnyPublisher<Bool, EosioError>
-
Promised based method for signing a transaction and then broadcasting it.
Returns Promise
. Declaration
Swift
public func signAndBroadcast(_: PMKNamespacer) -> Promise<Bool>
Parameters
_
Differentiates call signature from that of non-promise-returning function. Pass in
.promise
as the first parameter to call this method. -
Promised based method for signing a transaction.
Returns Promise
. Declaration
Swift
public func sign(_: PMKNamespacer) -> Promise<Bool>
Parameters
_
Differentiates call signature from that of non-promise-returning function. Pass in
.promise
as the first parameter to call this method. -
Promised based method for signing a transaction with available keys.
Returns Promise
. Declaration
Swift
public func sign(_: PMKNamespacer, availableKeys: [String]) -> Promise<Bool>
Parameters
_
Differentiates call signature from that of non-promise-returning function. Pass in
.promise
as the first parameter to call this method.availableKeys
An array of public key strings that correspond to the private keys availble for signing.
-
Promised based method for signing a transaction with publicKeys keys.
Returns Promise
. Declaration
Swift
public func sign(_: PMKNamespacer, publicKeys: [String]) -> Promise<Bool>
Parameters
_
Differentiates call signature from that of non-promise-returning function. Pass in
.promise
as the first parameter to call this method.publicKeys
An array of public key strings that correspond to the private keys to sign the transaction with.
-
Promised based method for broadcast a transaction.
Returns Promise
. Declaration
Swift
public func broadcast(_: PMKNamespacer) -> Promise<Bool>
Parameters
_
Differentiates call signature from that of non-promise-returning function. Pass in
.promise
as the first parameter to call this method. -
Promised based method to serialize a transaction.
Returns Promise.
Declaration
Swift
public func serializeTransaction(_: PMKNamespacer) -> Promise<Data>
Parameters
_
Differentiates call signature from that of non-promise-returning function. Pass in
.promise
as the first parameter to call this method. -
Promised based method to prepare a transaction.
Returns Promise
. Declaration
Swift
public func prepare(_: PMKNamespacer) -> Promise<Bool>
Parameters
_
Differentiates call signature from that of non-promise-returning function. Pass in
.promise
as the first parameter to call this method.