-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathTWSolanaTransaction.cpp
89 lines (65 loc) · 3.56 KB
/
TWSolanaTransaction.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.
#include "TrustWalletCore/TWSolanaTransaction.h"
#include "DataVector.h"
#include "rust/Wrapper.h"
using namespace TW;
TWData *_Nonnull TWSolanaTransactionUpdateBlockhashAndSign(TWString *_Nonnull encodedTx,
TWString *_Nonnull recentBlockhash,
const struct TWDataVector *_Nonnull privateKeys) {
auto& encodedTxRef = *reinterpret_cast<const std::string*>(encodedTx);
auto& recentBlockhashRef = *reinterpret_cast<const std::string*>(recentBlockhash);
Rust::TWStringWrapper encodedTxStr = encodedTxRef;
Rust::TWStringWrapper recentBlockhashStr = recentBlockhashRef;
Rust::TWDataVectorWrapper privateKeysVec = createFromTWDataVector(privateKeys);
Rust::TWDataWrapper output = Rust::tw_solana_transaction_update_blockhash_and_sign(encodedTxStr.get(),
recentBlockhashStr.get(),
privateKeysVec.get());
auto outputData = output.toDataOrDefault();
return TWDataCreateWithBytes(outputData.data(), outputData.size());
}
TWString *_Nullable TWSolanaTransactionGetComputeUnitPrice(TWString *_Nonnull encodedTx) {
auto& encodedTxRef = *reinterpret_cast<const std::string*>(encodedTx);
Rust::TWStringWrapper encodedTxStr = encodedTxRef;
Rust::TWStringWrapper maybePrice = Rust::tw_solana_transaction_get_compute_unit_price(encodedTxStr.get());
if (!maybePrice) {
return nullptr;
}
auto priceStr = maybePrice.toStringOrDefault();
return TWStringCreateWithUTF8Bytes(priceStr.c_str());
}
TWString *_Nullable TWSolanaTransactionGetComputeUnitLimit(TWString *_Nonnull encodedTx) {
auto& encodedTxRef = *reinterpret_cast<const std::string*>(encodedTx);
Rust::TWStringWrapper encodedTxStr = encodedTxRef;
Rust::TWStringWrapper maybeLimit = Rust::tw_solana_transaction_get_compute_unit_limit(encodedTxStr.get());
if (!maybeLimit) {
return nullptr;
}
auto limitStr = maybeLimit.toStringOrDefault();
return TWStringCreateWithUTF8Bytes(limitStr.c_str());
}
TWString *_Nullable TWSolanaTransactionSetComputeUnitPrice(TWString *_Nonnull encodedTx, TWString *_Nonnull price) {
auto& encodedTxRef = *reinterpret_cast<const std::string*>(encodedTx);
auto& priceRef = *reinterpret_cast<const std::string*>(price);
Rust::TWStringWrapper encodedTxStr = encodedTxRef;
Rust::TWStringWrapper priceStr = priceRef;
Rust::TWStringWrapper updatedTxStr = Rust::tw_solana_transaction_set_compute_unit_price(encodedTxStr.get(), priceStr.get());
if (!updatedTxStr) {
return nullptr;
}
auto updatedTx = updatedTxStr.toStringOrDefault();
return TWStringCreateWithUTF8Bytes(updatedTx.c_str());
}
TWString *_Nullable TWSolanaTransactionSetComputeUnitLimit(TWString *_Nonnull encodedTx, TWString *_Nonnull limit) {
auto& encodedTxRef = *reinterpret_cast<const std::string*>(encodedTx);
auto& limitRef = *reinterpret_cast<const std::string*>(limit);
Rust::TWStringWrapper encodedTxStr = encodedTxRef;
Rust::TWStringWrapper limitStr = limitRef;
Rust::TWStringWrapper updatedTxStr = Rust::tw_solana_transaction_set_compute_unit_limit(encodedTxStr.get(), limitStr.get());
if (!updatedTxStr) {
return nullptr;
}
auto updatedTx = updatedTxStr.toStringOrDefault();
return TWStringCreateWithUTF8Bytes(updatedTx.c_str());
}