Skip to content

Commit 2b07c52

Browse files
authored
chore(builder): improvements (#215)
1 parent 0746433 commit 2b07c52

27 files changed

Lines changed: 78 additions & 101 deletions

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
### Added
1111
- added Delegate Resignation Builder and Tests ([#207])
1212

13+
### Changed
14+
- improved transaction builder ([#215])
15+
1316
## [1.0.0] - 2020-02-13
1417

18+
### Added
19+
- added AIP-11 support for Core v.2.6 Transactions ([#198])
20+
1521
### Changed
1622
- removed use of monolithic `arkCrypto.h` header ([#190])
1723
- break up unit tests to support platforms with limited RAM ([#172])
1824

19-
### Added
20-
- added AIP-11 support for Core v.2.6 Transactions ([#198])
21-
2225
### Fixed
2326
- fixed `transaction::to_json` tests on ESP8266 ([#180])
2427
- fixed `transaction::to_array` tests on ESP8266 ([#178])
@@ -135,4 +138,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
135138
[#198]: https://github.com/ArkEcosystem/cpp-crypto/pull/198
136139
[1.0.0]: https://github.com/ArkEcosystem/cpp-crypto/compare/0.7.0...1.0.0
137140
[#207]: https://github.com/ArkEcosystem/cpp-crypto/pull/207
141+
[#215]: https://github.com/ArkEcosystem/cpp-crypto/pull/215
138142
[unreleased]: https://github.com/ArkEcosystem/cpp-crypto/compare/1.0.0...develop

docs/INSTALL_ARDUINO.MD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ void createBridgechainTransaction() {
237237
const Configuration cfg(BridgechainNetwork);
238238

239239
// Use the Transaction Builder to make a transaction.
240-
const auto bridgechainTransaction = builder::Transfer()
240+
const auto bridgechainTransaction = builder::Transfer(cfg)
241241
.recipientId("D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib")
242242
.vendorField("this is a custom bridgechain transaction")
243243
.sign(Passphrase)
244244
.secondSign(SecondPassphrase)
245-
.build(cfg);
245+
.build();
246246

247247
// Create and Print the Json representation of the Transaction.
248248
const auto transactionJson = bridgechainTransaction.toJson();

docs/cpp.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ This project is still under development. This page will get more content as the
2626
```cpp
2727
// Default Configuration is Devnet
2828
const auto transaction = builder::Transfer()
29-
.type(0)
3029
.nonce(1)
3130
.senderPublicKey(fixtures::PublicKeyBytes.data())
3231
.vendorField("this is a devnet transaction")
@@ -41,20 +40,19 @@ const auto transaction = builder::Transfer()
4140
### Mainnet
4241

4342
```cpp
44-
// Use the Configuration Class to create a Mainnet Transaction
45-
const Configuration mainnetCfg(Mainnet);
43+
// Also pass the Network as a builder constructor argument
4644

47-
const auto transaction = builder::Transfer()
48-
.type(0)
45+
#include "networks/mainnet.hpp"
46+
47+
const auto transaction = builder::Transfer(Mainnet)
4948
.nonce(1)
50-
.senderPublicKey(fixtures::PublicKeyBytes.data())
5149
.vendorField("this is a devnet transaction")
5250
.amount(100000000ULL)
5351
.expiration(0)
5452
.recipientId("D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib")
5553
.sign("this is a top secret passphrase")
5654
.secondSign("this is a top secret passphrase too")
57-
.build(mainnetCfg);
55+
.build();
5856
```
5957

6058
### BridgeChain Transaction
@@ -77,17 +75,15 @@ const uint8_t radiansRecipient[] = {
7775
65, 29, 252, 105, 181, 76, 127, 233, 1, 233, 29,
7876
90, 154, 183, 131, 136, 100, 94, 36, 39, 234 };
7977

80-
auto transaction = builder::Transfer()
81-
.type(0)
78+
auto transaction = builder::Transfer(radiansCfg)
8279
.nonce(1)
83-
.senderPublicKey(senderPublicKeyBytes.data())
8480
.vendorField("this is a Radians transaction")
8581
.amount(100000000ULL)
8682
.expiration(0)
8783
.recipientId(radiansRecipient)
8884
.sign("this is a top secret passphrase")
8985
.secondSign("this is a top secret passphrase too")
90-
.build(radiansCfg);
86+
.build();
9187
```
9288
9389
### With custom Fees
@@ -106,17 +102,15 @@ const FeePolicy customFees = {
106102
107103
const Configuration customCfg(Radians, MyCustomFees);
108104
109-
auto transaction = builder::Transfer()
110-
.type(0)
105+
auto transaction = builder::Transfer(customCfg)
111106
.nonce(1)
112-
.senderPublicKey(senderPublicKeyBytes.data())
113107
.vendorField("this is a Radians transaction")
114108
.amount(100000000ULL)
115109
.expiration(0)
116110
.recipientId(radiansRecipient)
117111
.sign("this is a top secret passphrase")
118112
.secondSign("this is a top secret passphrase too")
119-
.build(customCfg);
113+
.build();
120114
```
121115

122116
### Sign a Transactions
@@ -539,12 +533,12 @@ void createBridgechainTransaction() {
539533
const Configuration cfg(BridgechainNetwork);
540534

541535
// Use the Transaction Builder to make a transaction.
542-
const auto bridgechainTransaction = builder::Transfer()
536+
const auto bridgechainTransaction = builder::Transfer(cfg)
543537
.recipientId("D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib")
544538
.vendorField("this is a custom bridgechain transaction")
545539
.sign(Passphrase)
546540
.secondSign(SecondPassphrase)
547-
.build(cfg);
541+
.build();
548542

549543
// Create and Print the Json representation of the Transaction.
550544
const auto transactionJson = bridgechainTransaction.toJson();

examples/arduino/ESP32/ESP32.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ void createBridgechainTransaction() {
181181
const Configuration cfg(BridgechainNetwork);
182182

183183
// Use the Transaction Builder to make a transaction.
184-
const auto bridgechainTransaction = builder::Transfer()
184+
const auto bridgechainTransaction = builder::Transfer(cfg)
185185
.recipientId("D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib")
186186
.vendorField("this is a custom bridgechain transaction")
187187
.sign(Passphrase)
188188
.secondSign(SecondPassphrase)
189-
.build(cfg);
189+
.build();
190190

191191
// Create and Print the Json representation of the Transaction.
192192
const auto transactionJson = bridgechainTransaction.toJson();

examples/arduino/ESP8266/ESP8266.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ void createBridgechainTransaction() {
160160
const Configuration cfg(BridgechainNetwork);
161161

162162
// Use the Transaction Builder to make a transaction.
163-
const auto bridgechainTransaction = builder::Transfer()
163+
const auto bridgechainTransaction = builder::Transfer(cfg)
164164
.recipientId("D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib")
165165
.vendorField("this is a custom bridgechain transaction")
166166
.sign(Passphrase)
167-
.build(cfg);
167+
.build();
168168

169169
// Create and Print the Json representation of the Transaction.
170170
const auto transactionJson = bridgechainTransaction.toJson();

src/include/cpp-crypto/common/configuration.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class Configuration : public managers::NetworkManager,
2424
////////////////////////////////////////////////////////////////////////////
2525
// Default initialization: ARK Devnet w/StaticFees
2626
Configuration() = default;
27-
explicit Configuration(const Network &network);
28-
explicit Configuration(const FeePolicy &policy);
27+
Configuration(const Network &network);
28+
Configuration(const FeePolicy &policy);
2929
Configuration(const Network &network, const FeePolicy &policy);
3030

3131
////////////////////////////////////////////////////////////////////////////

src/include/cpp-crypto/transactions/builders/delegate_registration.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ class DelegateRegistration : public Common<DelegateRegistration> {
6363
}
6464

6565
////////////////////////////////////////////////////////////////////////////
66-
DelegateRegistration() {
66+
DelegateRegistration(const Configuration &config = {}) {
6767
this->transaction.data.type = DELEGATE_REGISTRATION_TYPE;
68+
this->configure(config);
6869
}
6970
};
7071

src/include/cpp-crypto/transactions/builders/delegate_resignation.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ class DelegateResignation;
2424
////////////////////////////////////////////////////////////////////////////////
2525
class DelegateResignation : public Common<DelegateResignation> {
2626
public:
27-
DelegateResignation() {
27+
DelegateResignation(const Configuration &config = {}) {
2828
this->transaction.data.type = DELEGATE_RESIGNATION_TYPE;
29+
this->configure(config);
2930
}
3031
};
3132

src/include/cpp-crypto/transactions/builders/htlc_claim.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ class HtlcClaim : public Common<HtlcClaim> {
5050
}
5151

5252
////////////////////////////////////////////////////////////////////////////
53-
HtlcClaim() {
53+
HtlcClaim(const Configuration &config = {}) {
5454
this->transaction.data.type = HTLC_CLAIM_TYPE;
55+
this->configure(config);
5556
}
5657
};
5758

src/include/cpp-crypto/transactions/builders/htlc_lock.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ class HtlcLock : public Common<HtlcLock> {
8888
}
8989

9090
////////////////////////////////////////////////////////////////////////////
91-
HtlcLock() {
91+
HtlcLock(const Configuration &config = {}) {
9292
this->transaction.data.type = HTLC_LOCK_TYPE;
93+
this->configure(config);
9394
}
9495
};
9596

0 commit comments

Comments
 (0)