Skip to content

Commit afcd2d3

Browse files
sleepdefic1tfaustbrian
authored andcommitted
chore(transaction): update amounts json (#111)
1 parent 56864e0 commit afcd2d3

11 files changed

Lines changed: 250 additions & 179 deletions

File tree

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/include/cpp-crypto/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/include/cpp-crypto/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 = "";

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/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 'fee' 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) {

test/transactions/builder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ TEST(transactions, build_transfer) {
1313
ASSERT_EQ(0, actual.type);
1414
ASSERT_EQ(defaults::Fees::StaticFeePolicy()[actual.type], actual.fee);
1515
ASSERT_STREQ("D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib",
16-
actual.recipientId.c_str());
16+
actual.recipient.c_str());
1717
ASSERT_EQ(100000000ULL, actual.amount);
1818
ASSERT_TRUE(actual.vendorField.empty());
1919
}
@@ -40,7 +40,7 @@ TEST(transactions, build_transfer_custom_network) {
4040
ASSERT_EQ(0, transaction.type);
4141
ASSERT_EQ(myCustomConfiguration.getFee(transaction.type), transaction.fee);
4242
ASSERT_STREQ("D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib",
43-
transaction.recipientId.c_str());
43+
transaction.recipient.c_str());
4444
ASSERT_EQ(100000000ULL, transaction.amount);
4545
ASSERT_STREQ("this is a custom bridgechain transaction",
4646
transaction.vendorField.c_str());
@@ -56,7 +56,7 @@ TEST(transactions, build_empty_transaction) {
5656
"",
5757
"Secret passphrase");
5858

59-
ASSERT_TRUE(shouldBeEmpty.recipientId.empty());
59+
ASSERT_TRUE(shouldBeEmpty.recipient.empty());
6060
ASSERT_EQ(0ULL, shouldBeEmpty.amount);
6161
ASSERT_FALSE(shouldBeEmpty.verify());
6262
}

test/transactions/deserializer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ TEST(transactions, deserialize_transfer) { // NOLINT
2626
ASSERT_STREQ(
2727
"ecf558fbddd62ae42edcfcba02f402d987a94b72a7636ef1121e8625487e2a1e",
2828
actual.id.c_str());
29-
ASSERT_STREQ("D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", actual.recipientId.c_str());
29+
ASSERT_STREQ("D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", actual.recipient.c_str());
3030
ASSERT_STREQ(
3131
"304402205616d6e361439d67a5c2067bbfc8fce61b93061a4fa113315a1c5cf965ff6f3202200a1d99caaa98aeebcec04edd5365352500addb830c79f49b9de484ec616bb1e1",
3232
actual.signature.c_str());
@@ -65,10 +65,10 @@ TEST(transactions, deserialize_second_signature_registration) { // NOLINT
6565
actual.signature.c_str());
6666
ASSERT_TRUE(actual.verify());
6767

68-
// special case as the type 1 transaction itself has no recipientId
68+
// special case as the type 1 transaction itself has no recipient
6969
const auto publicKey = Ark::Crypto::Identities::PublicKey::fromHex(actual.senderPublicKey.c_str());
7070
const auto address = Ark::Crypto::Identities::Address::fromPublicKey(publicKey, actual.network);
71-
ASSERT_STREQ(address.toString().c_str(), actual.recipientId.c_str());
71+
ASSERT_STREQ(address.toString().c_str(), actual.recipient.c_str());
7272
}
7373

7474
/**/
@@ -131,7 +131,7 @@ TEST(transactions, deserialize_vote) { // NOLINT
131131
ASSERT_TRUE(0ULL == actual.amount);
132132
ASSERT_EQ(0, actual.expiration);
133133
ASSERT_STREQ("16f28a180cd6f3ea46c10f358a457989e956e9d355258230d0c7b07acec10b73", actual.id.c_str());
134-
ASSERT_STREQ("D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", actual.recipientId.c_str());
134+
ASSERT_STREQ("D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", actual.recipient.c_str());
135135

136136
std::vector<std::string> votes = {std::string("+022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d")};
137137
ASSERT_EQ(1, actual.asset.votes.size());
@@ -207,8 +207,8 @@ TEST(transactions, deserialize_multi_signature_registration) { // NOLINT
207207

208208
ASSERT_TRUE(actual.verify());
209209

210-
// special case as the type 4 transaction itself has no recipientId
210+
// special case as the type 4 transaction itself has no recipient
211211
const auto publicKey = Ark::Crypto::Identities::PublicKey::fromHex(actual.senderPublicKey.c_str());
212212
const auto address = Ark::Crypto::Identities::Address::fromPublicKey(publicKey, actual.network);
213-
ASSERT_STREQ(address.toString().c_str(), actual.recipientId.c_str());
213+
ASSERT_STREQ(address.toString().c_str(), actual.recipient.c_str());
214214
}

test/transactions/serializer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ TEST(transactions, serialize_transfer) { // NOLINT
1111
transaction.fee = 10000000ULL;
1212
transaction.amount = 200000000ULL;
1313
transaction.timestamp = 41443847UL;
14-
transaction.recipientId = "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib";
14+
transaction.recipient = "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib";
1515
transaction.senderPublicKey = "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192";
1616
transaction.vendorField = "Hello World";
1717
transaction.signature = "304402205616d6e361439d67a5c2067bbfc8fce61b93061a4fa113315a1c5cf965ff6f3202200a1d99caaa98aeebcec04edd5365352500addb830c79f49b9de484ec616bb1e1";
@@ -83,7 +83,7 @@ TEST(transactions, serialize_vote) { // NOLINT
8383
transaction.type = 3;
8484
transaction.fee = 100000000ULL;
8585
transaction.timestamp = 41269366UL;
86-
transaction.recipientId = "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib";
86+
transaction.recipient = "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib";
8787
transaction.senderPublicKey = "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192";
8888
transaction.signature = "304402204b8bb403e2db7f9599d46d0f5d39f8bb1d0663d875af7ec1154448e98466e86302201e92fb57e13fb729b07e1027fa3d6e3f28e0d5828ed2d7c53a5e8db08cb6d068";
8989
transaction.secondSignature = "304402201329882762a42d1af9079c822a9e3feefa47b7476b0afe61440637408958a64402206da179b08e31d9c784fbb23abe2c9b50353ed7881dc29787a5e8ecbee2dfda66";

0 commit comments

Comments
 (0)