Skip to content

Commit 1f00abf

Browse files
sleepdefic1tfaustbrian
authored andcommitted
chore(transaction): update amounts json (#112)
1 parent 4ba1412 commit 1f00abf

File tree

7 files changed

+31
-29
lines changed

7 files changed

+31
-29
lines changed

src/identities/address.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ std::string Ark::Crypto::Identities::Address::base58encode(
121121

122122
std::vector<uint8_t> Ark::Crypto::Identities::Address::bytesFromBase58Check(
123123
const char* address) {
124-
std::vector<std::uint8_t> recipientIdBytes;
125-
recipientIdBytes.resize(Ripemd160::HASH_LEN);
124+
std::vector<std::uint8_t> recipientBytes;
125+
recipientBytes.resize(Ripemd160::HASH_LEN);
126126
uint8_t version = 0;
127127
Base58Check::pubkeyHashFromBase58Check(
128128
address,
129-
&recipientIdBytes[0],
129+
&recipientBytes[0],
130130
&version);
131-
recipientIdBytes.insert(recipientIdBytes.begin(), version);
131+
recipientBytes.insert(recipientBytes.begin(), version);
132132

133-
return recipientIdBytes;
133+
return recipientBytes;
134134
}

src/transactions/builder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Crypto {
1717
namespace Transactions {
1818

1919
Transaction Builder::buildTransfer(
20-
std::string recipientId,
20+
std::string recipient,
2121
uint64_t amount,
2222
std::string vendorField,
2323
std::string passphrase,
@@ -28,7 +28,7 @@ Transaction Builder::buildTransfer(
2828

2929
transaction.type = defaults::TransactionTypes::Transfer;
3030
transaction.fee = configuration.getFee(defaults::TransactionTypes::Transfer);
31-
transaction.recipientId = std::move(recipientId);
31+
transaction.recipient = std::move(recipient);
3232
transaction.amount = amount;
3333
transaction.vendorField = std::move(vendorField);
3434

@@ -93,7 +93,7 @@ Transaction Builder::buildVote(
9393
const auto recipient = Identities::Address::fromPassphrase(
9494
passphrase.c_str(),
9595
configuration.getNetwork().version());
96-
transaction.recipientId = recipient.toString();
96+
transaction.recipient = recipient.toString();
9797

9898
return sign(transaction,
9999
std::move(passphrase),
@@ -121,7 +121,7 @@ Transaction Builder::buildMultiSignatureRegistration(
121121
const auto recipient = Identities::Address::fromPassphrase(
122122
passphrase.c_str(),
123123
configuration.getNetwork().version());
124-
transaction.recipientId = recipient.toString();
124+
transaction.recipient = recipient.toString();
125125

126126
return sign(
127127
transaction,

src/transactions/builder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Builder {
3131
* validation will fail.
3232
**/
3333
static Transaction buildTransfer(
34-
std::string recipientId,
34+
std::string recipient,
3535
uint64_t amount,
3636
std::string vendorField,
3737
std::string passphrase,

src/transactions/deserializer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void Deserializer::deserializeTransfer(
107107
Transaction& transaction) {
108108
unpack(&transaction.amount, &this->_binary[_assetOffset / 2]);
109109
unpack(&transaction.expiration, &this->_binary[_assetOffset / 2 + 8]);
110-
transaction.recipientId = Identities::Address::base58encode(
110+
transaction.recipient = Identities::Address::base58encode(
111111
&this->_binary[(_assetOffset / 2) + 12]);
112112

113113
_assetOffset += (8 + 4 + 21) * 2;
@@ -253,7 +253,7 @@ void Deserializer::handleVersionOne(
253253
const auto address = Identities::Address::fromPublicKey(
254254
publicKey,
255255
transaction.network);
256-
transaction.recipientId = address.toString();
256+
transaction.recipient = address.toString();
257257
};
258258

259259
if (transaction.type == defaults::TransactionTypes::MultiSignatureRegistration) {
@@ -280,7 +280,7 @@ void Deserializer::handleVersionOne(
280280
const auto address = Identities::Address::fromPublicKey(
281281
publicKey,
282282
transaction.network);
283-
transaction.recipientId = address.toString();
283+
transaction.recipient = address.toString();
284284
};
285285
}
286286

src/transactions/serializer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ void Serializer::serializeTransfer(
114114
pack(bytes, _transaction.amount);
115115
pack(bytes, _transaction.expiration);
116116

117-
std::vector<uint8_t> recipientIdBytes = Identities::Address::bytesFromBase58Check(
118-
_transaction.recipientId.c_str());
117+
std::vector<uint8_t> recipientBytes = Identities::Address::bytesFromBase58Check(
118+
_transaction.recipient.c_str());
119119
bytes.insert(
120120
bytes.end(),
121-
recipientIdBytes.begin(),
122-
recipientIdBytes.end());
121+
recipientBytes.begin(),
122+
recipientBytes.end());
123123
}
124124

125125
/**/

src/transactions/transaction.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ std::vector<uint8_t> Ark::Crypto::Transactions::Transaction::toBytes(
112112
std::begin(senderKeyBytes),
113113
std::end(senderKeyBytes));
114114

115-
const auto skipRecipientId =
115+
const auto skiprecipient =
116116
type == defaults::TransactionTypes::SecondSignatureRegistration
117117
|| type ==defaults::TransactionTypes::MultiSignatureRegistration;
118118

119-
if (!this->recipientId.empty() && !skipRecipientId) {
120-
std::vector<std::uint8_t> recipientIdBytes = Address::bytesFromBase58Check(
121-
this->recipientId.c_str());
119+
if (!this->recipient.empty() && !skiprecipient) {
120+
std::vector<std::uint8_t> recipientBytes = Address::bytesFromBase58Check(
121+
this->recipient.c_str());
122122
bytes.insert(
123123
std::end(bytes),
124-
std::begin(recipientIdBytes),
125-
std::end(recipientIdBytes));
124+
std::begin(recipientBytes),
125+
std::end(recipientBytes));
126126
} else {
127127
std::vector<uint8_t> filler(21, 0);
128128
bytes.insert(
@@ -301,7 +301,7 @@ std::map<std::string, std::string> Ark::Crypto::Transactions::Transaction::toArr
301301
{ "fee", fee },
302302
{ "id", this->id },
303303
{ "network", network },
304-
{ "recipientId", this->recipientId },
304+
{ "recipient", this->recipient },
305305
{ "secondSignature", this->secondSignature },
306306
{ "senderPublicKey", this->senderPublicKey },
307307
{ "signature", this->signature },
@@ -323,7 +323,8 @@ std::string Ark::Crypto::Transactions::Transaction::toJson() {
323323
DynamicJsonDocument doc(docCapacity);
324324

325325
// Amount
326-
doc["amount"] = strtoull(txArray["amount"].c_str(), nullptr, 10);
326+
// >= Core v.2.5 'amount' json is string-type
327+
doc["amount"] = txArray["amount"];
327328

328329
// Asset
329330
if (this->type == 0) {
@@ -365,7 +366,8 @@ std::string Ark::Crypto::Transactions::Transaction::toJson() {
365366
};
366367

367368
// Fee
368-
doc["fee"] = strtoull(txArray["fee"].c_str(), nullptr, 10);
369+
// >= Core v.2.5 'amount' json is string-type
370+
doc["fee"] = txArray["fee"];
369371

370372
// Id
371373
doc["id"] = txArray["id"];
@@ -375,8 +377,8 @@ std::string Ark::Crypto::Transactions::Transaction::toJson() {
375377
doc["network"] = atoi(txArray["network"].c_str());
376378
};
377379

378-
// RecipientId
379-
doc["recipientId"] = txArray["recipientId"];
380+
// Recipient
381+
doc["recipient"] = txArray["recipient"];
380382

381383
// SecondSignature
382384
if (std::strlen(txArray["secondSignature"].c_str()) > 0) {

src/transactions/transaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Transaction {
6363
uint32_t timelock_type = 0;
6464
std::vector<std::string> signatures = {};
6565
std::string id = "";
66-
std::string recipientId = "";
66+
std::string recipient = "";
6767
std::string senderPublicKey = "";
6868
std::string signature = "";
6969
std::string secondSignature = "";

0 commit comments

Comments
 (0)