spb/os-vault Public
Self-custody, multi-chain crypto wallet for macOS. One recovery phrase, six chain families, zero API keys — nothing leaves your Mac.
Swift 96%
Shell 3.4%
Makefile 0.6%
1import WalletCoreC2import Foundation3// SPDX-License-Identifier: Apache-2.04//5// Copyright © 2017 Trust Wallet.6//7// This is a GENERATED FILE, changes made here WILL BE LOST.8//910import Foundation111213public final class SolanaTransaction {1415 /// Decode Solana transaction, update the recent blockhash and re-sign the transaction.16 /// 17 /// # Warning18 /// 19 /// This is a temporary solution. It will be removed when `Solana.proto` supports20 /// direct transaction signing.21 /// 22 /// - Parameter encoded_tx: base64 encoded Solana transaction.23 /// - Parameter recent_blockhash: base58 encoded recent blockhash.24 /// - Parameter private_keys: list of private keys that should be used to re-sign the transaction.25 /// - Returns: serialized `Solana::Proto::SigningOutput`.26 public static func updateBlockhashAndSign(encodedTx: String, recentBlockhash: String, privateKeys: DataVector) -> Data? {27 let encodedTxString = TWStringCreateWithNSString(encodedTx)28 defer {29 TWStringDelete(encodedTxString)30 }31 let recentBlockhashString = TWStringCreateWithNSString(recentBlockhash)32 defer {33 TWStringDelete(recentBlockhashString)34 }35 guard let result = TWSolanaTransactionUpdateBlockhashAndSign(encodedTxString, recentBlockhashString, privateKeys.rawValue) else {36 return nil37 }38 return TWDataNSData(result)39 }4041 /// Try to find a `ComputeBudgetInstruction::SetComputeUnitPrice` instruction in the given transaction,42 /// and returns the specified Unit Price.43 /// 44 /// - Parameter encoded_tx: base64 encoded Solana transaction.45 /// - Returns: nullable Unit Price as a decimal string. Null if no instruction found.46 public static func getComputeUnitPrice(encodedTx: String) -> String? {47 let encodedTxString = TWStringCreateWithNSString(encodedTx)48 defer {49 TWStringDelete(encodedTxString)50 }51 guard let result = TWSolanaTransactionGetComputeUnitPrice(encodedTxString) else {52 return nil53 }54 return TWStringNSString(result)55 }5657 /// Try to find a `ComputeBudgetInstruction::SetComputeUnitLimit` instruction in the given transaction,58 /// and returns the specified Unit Limit.59 /// 60 /// - Parameter encoded_tx: base64 encoded Solana transaction.61 /// - Returns: nullable Unit Limit as a decimal string. Null if no instruction found.62 public static func getComputeUnitLimit(encodedTx: String) -> String? {63 let encodedTxString = TWStringCreateWithNSString(encodedTx)64 defer {65 TWStringDelete(encodedTxString)66 }67 guard let result = TWSolanaTransactionGetComputeUnitLimit(encodedTxString) else {68 return nil69 }70 return TWStringNSString(result)71 }7273 /// Adds or updates a `ComputeBudgetInstruction::SetComputeUnitPrice` instruction of the given transaction,74 /// and returns the updated transaction.75 /// 76 /// - Parameter encoded_tx: base64 encoded Solana transaction.77 /// \price Unit Price as a decimal string.78 /// - Returns: base64 encoded Solana transaction. Null if an error occurred.79 public static func setComputeUnitPrice(encodedTx: String, price: String) -> String? {80 let encodedTxString = TWStringCreateWithNSString(encodedTx)81 defer {82 TWStringDelete(encodedTxString)83 }84 let priceString = TWStringCreateWithNSString(price)85 defer {86 TWStringDelete(priceString)87 }88 guard let result = TWSolanaTransactionSetComputeUnitPrice(encodedTxString, priceString) else {89 return nil90 }91 return TWStringNSString(result)92 }9394 /// Adds or updates a `ComputeBudgetInstruction::SetComputeUnitLimit` instruction of the given transaction,95 /// and returns the updated transaction.96 /// 97 /// - Parameter encoded_tx: base64 encoded Solana transaction.98 /// \limit Unit Limit as a decimal string.99 /// - Returns: base64 encoded Solana transaction. Null if an error occurred.100 public static func setComputeUnitLimit(encodedTx: String, limit: String) -> String? {101 let encodedTxString = TWStringCreateWithNSString(encodedTx)102 defer {103 TWStringDelete(encodedTxString)104 }105 let limitString = TWStringCreateWithNSString(limit)106 defer {107 TWStringDelete(limitString)108 }109 guard let result = TWSolanaTransactionSetComputeUnitLimit(encodedTxString, limitString) else {110 return nil111 }112 return TWStringNSString(result)113 }114115 /// Adds fee payer to the given transaction, and returns the updated transaction.116 /// 117 /// - Parameter encoded_tx: base64 encoded Solana transaction.118 /// - Parameter fee_payer: fee payer account address. Must be a base58 encoded public key. It must NOT be in the account list yet.119 /// - Returns: base64 encoded Solana transaction. Null if an error occurred.120 public static func setFeePayer(encodedTx: String, feePayer: String) -> String? {121 let encodedTxString = TWStringCreateWithNSString(encodedTx)122 defer {123 TWStringDelete(encodedTxString)124 }125 let feePayerString = TWStringCreateWithNSString(feePayer)126 defer {127 TWStringDelete(feePayerString)128 }129 guard let result = TWSolanaTransactionSetFeePayer(encodedTxString, feePayerString) else {130 return nil131 }132 return TWStringNSString(result)133 }134135 /// Inserts an instruction to the given transaction at the specified position, returning the updated transaction.136 /// 137 /// - Parameter encoded_tx: base64 encoded Solana transaction.138 /// - Parameter insert_at: index where the instruction should be inserted. If you don't care about the position, use -1.139 /// - Parameter instruction: json encoded instruction. Here is an example: {"programId":"11111111111111111111111111111111","accounts":[{"pubkey":"YUz1AupPEy1vttBeDS7sXYZFhQJppcXMzjDiDx18Srf","isSigner":true,"isWritable":true},{"pubkey":"d8DiHEeHKdXkM2ZupT86mrvavhmJwUZjHPCzMiB5Lqb","isSigner":false,"isWritable":true}],"data":"3Bxs4Z6oyhaczjLK"}140 /// - Returns: base64 encoded Solana transaction. Null if an error occurred.141 public static func insertInstruction(encodedTx: String, insertAt: Int32, instruction: String) -> String? {142 let encodedTxString = TWStringCreateWithNSString(encodedTx)143 defer {144 TWStringDelete(encodedTxString)145 }146 let instructionString = TWStringCreateWithNSString(instruction)147 defer {148 TWStringDelete(instructionString)149 }150 guard let result = TWSolanaTransactionInsertInstruction(encodedTxString, insertAt, instructionString) else {151 return nil152 }153 return TWStringNSString(result)154 }155156 /// Inserts a SOL transfer instruction to the given transaction at the specified position, returning the updated transaction.157 /// Please note that compute price and limit instructions should always be the first instructions if they are present in the transaction.158 /// 159 /// - Parameter encoded_tx: base64 encoded Solana transaction.160 /// - Parameter insert_at: index where the instruction should be inserted. If you don't care about the position, use -1.161 /// - Parameter from: sender account from which the lamports will be debited.162 /// - Parameter to: receiver account to which the lamports will be transferred.163 /// - Parameter lamports: amount of lamports to transfer, as a decimal string.164 /// - Returns: base64 encoded Solana transaction. Null if an error occurred.165 public static func insertTransferInstruction(encodedTx: String, insertAt: Int32, from: String, to: String, lamports: String) -> String? {166 let encodedTxString = TWStringCreateWithNSString(encodedTx)167 defer {168 TWStringDelete(encodedTxString)169 }170 let fromString = TWStringCreateWithNSString(from)171 defer {172 TWStringDelete(fromString)173 }174 let toString = TWStringCreateWithNSString(to)175 defer {176 TWStringDelete(toString)177 }178 let lamportsString = TWStringCreateWithNSString(lamports)179 defer {180 TWStringDelete(lamportsString)181 }182 guard let result = TWSolanaTransactionInsertTransferInstruction(encodedTxString, insertAt, fromString, toString, lamportsString) else {183 return nil184 }185 return TWStringNSString(result)186 }187188 let rawValue: OpaquePointer189190 init(rawValue: OpaquePointer) {191 self.rawValue = rawValue192 }193194195}196