9
9
import com .bloxbean .cardano .client .backend .api .BackendService ;
10
10
import com .bloxbean .cardano .client .cip .cip20 .MessageMetadata ;
11
11
import com .bloxbean .cardano .client .common .model .Networks ;
12
+ import com .bloxbean .cardano .client .crypto .Bech32 ;
12
13
import com .bloxbean .cardano .client .exception .CborSerializationException ;
13
14
import com .bloxbean .cardano .client .function .helper .SignerProviders ;
14
15
import com .bloxbean .cardano .client .metadata .Metadata ;
@@ -39,6 +40,7 @@ public class QuickTxBuilderIT extends QuickTxBaseIT {
39
40
DefaultWalletUtxoSupplier walletUtxoSupplier ;
40
41
Wallet wallet1 ;
41
42
Wallet wallet2 ;
43
+ Wallet wallet3 ;
42
44
43
45
static Account topupAccount ;
44
46
@@ -58,9 +60,12 @@ void setup() {
58
60
utxoSupplier = getUTXOSupplier ();
59
61
60
62
String wallet1Mnemonic = "clog book honey force cricket stamp until seed minimum margin denial kind volume undo simple federal then jealous solid legal crucial crazy acoustic thank" ;
61
- wallet1 = new Wallet (Networks .testnet (), wallet1Mnemonic );
63
+ wallet1 = Wallet . createFromMnemonic (Networks .testnet (), wallet1Mnemonic );
62
64
String wallet2Mnemonic = "theme orphan remind output arrive lobster decorate ten gap piece casual distance attend total blast dilemma damp punch pride file limit soldier plug canoe" ;
63
- wallet2 = new Wallet (Networks .testnet (), wallet2Mnemonic );
65
+ wallet2 = Wallet .createFromMnemonic (Networks .testnet (), wallet2Mnemonic );
66
+
67
+ String acctSk = "acct_xsk1azc6gn5zkdprp4gkapmhdckykphjl62rm9224699ut5z6xcaa9p4hv5hmjfgcrzk72tnsqh6dw0njekdjpsv8nv5h5hk6lpd4ag62zenwhzqs205kfurd7kgs8fm5gx4l4j8htutwj060kyp5y5kgw55qc8lsltd" ;
68
+ wallet3 = Wallet .createFromAccountKey (Networks .testnet (), Bech32 .decode (acctSk ).data );
64
69
65
70
walletUtxoSupplier = new DefaultWalletUtxoSupplier (backendService .getUtxoService (), wallet1 );
66
71
}
@@ -71,15 +76,15 @@ void simplePayment() {
71
76
metadata .put (BigInteger .valueOf (100 ), "This is first metadata" );
72
77
metadata .putNegative (200 , -900 );
73
78
79
+ wallet1 .setSearchUtxoByAddrVkh (true );
74
80
//topup wallet
75
- splitPaymentBetweenAddress (topupAccount , wallet1 , 20 , Double .valueOf (50000 ));
76
-
81
+ splitPaymentBetweenAddress (topupAccount , wallet1 , 20 , Double .valueOf (3000 ), true );
77
82
78
83
UtxoSupplier walletUtxoSupplier = new DefaultWalletUtxoSupplier (backendService .getUtxoService (), wallet1 );
79
84
QuickTxBuilder quickTxBuilder = new QuickTxBuilder (backendService , walletUtxoSupplier );
80
85
81
86
Tx tx = new Tx ()
82
- .payToAddress (wallet2 .getBaseAddress (0 ).getAddress (), Amount .ada (50000 ))
87
+ .payToAddress (wallet2 .getBaseAddress (0 ).getAddress (), Amount .ada (2000 ))
83
88
.from (wallet1 );
84
89
85
90
Result <String > result = quickTxBuilder .compose (tx )
@@ -99,7 +104,7 @@ void simplePayment() {
99
104
@ Test
100
105
void simplePayment_withIndexesToScan () {
101
106
String mnemonic = "buzz sentence empty coffee manage grid claw street misery deputy direct seek tortoise wedding stay twist crew august omit taste expect obscure abandon iron" ;
102
- Wallet wallet = new Wallet (Networks .testnet (), mnemonic );
107
+ Wallet wallet = Wallet . createFromMnemonic (Networks .testnet (), mnemonic );
103
108
wallet .setIndexesToScan (new int []{5 , 30 , 45 });
104
109
105
110
//topup index 5, 45
@@ -169,7 +174,7 @@ void utxoTest() {
169
174
assertTrue (!utxos .isEmpty ());
170
175
}
171
176
172
- void splitPaymentBetweenAddress (Account topupAccount , Wallet receiverWallet , int totalAddresses , Double adaAmount ) {
177
+ void splitPaymentBetweenAddress (Account topupAccount , Wallet receiverWallet , int totalAddresses , Double adaAmount , boolean enableEntAddrPayment ) {
173
178
// Create an amount array with no of totalAddresses with random distribution of split amounts
174
179
Double [] amounts = new Double [totalAddresses ];
175
180
Double remainingAmount = adaAmount ;
@@ -187,7 +192,15 @@ void splitPaymentBetweenAddress(Account topupAccount, Wallet receiverWallet, int
187
192
int currentIndex = 0 ;
188
193
189
194
for (int i = 0 ; i < totalAddresses ; i ++) {
190
- addresses [i ] = receiverWallet .getBaseAddressString (currentIndex );
195
+ if (enableEntAddrPayment ) {
196
+ if (i % 2 == 0 )
197
+ addresses [i ] = receiverWallet .getBaseAddressString (currentIndex );
198
+ else
199
+ addresses [i ] = receiverWallet .getEntAddress (currentIndex ).toBech32 ();
200
+ } else {
201
+ addresses [i ] = receiverWallet .getBaseAddressString (currentIndex );
202
+ }
203
+
191
204
currentIndex += random .nextInt (20 ) + 1 ;
192
205
}
193
206
@@ -205,4 +218,34 @@ void splitPaymentBetweenAddress(Account topupAccount, Wallet receiverWallet, int
205
218
206
219
System .out .println (result );
207
220
}
221
+
222
+ @ Test
223
+ void simplePayment_fromAccountKey () {
224
+ Metadata metadata = MetadataBuilder .createMetadata ();
225
+ metadata .put (BigInteger .valueOf (100 ), "This is first metadata" );
226
+ metadata .putNegative (200 , -900 );
227
+
228
+ //topup wallet
229
+ splitPaymentBetweenAddress (topupAccount , wallet3 , 20 , Double .valueOf (3000 ), false );
230
+
231
+ UtxoSupplier walletUtxoSupplier = new DefaultWalletUtxoSupplier (backendService .getUtxoService (), wallet3 );
232
+ QuickTxBuilder quickTxBuilder = new QuickTxBuilder (backendService , walletUtxoSupplier );
233
+
234
+ Tx tx = new Tx ()
235
+ .payToAddress (wallet2 .getBaseAddress (0 ).getAddress (), Amount .ada (2000 ))
236
+ .from (wallet3 );
237
+
238
+ Result <String > result = quickTxBuilder .compose (tx )
239
+ .withSigner (SignerProviders .signerFrom (wallet3 ))
240
+ .withTxInspector (txn -> {
241
+ System .out .println (JsonUtil .getPrettyJson (txn ));
242
+ })
243
+ .complete ();
244
+
245
+ System .out .println (result );
246
+ assertTrue (result .isSuccessful ());
247
+ waitForTransaction (result );
248
+
249
+ checkIfUtxoAvailable (result .getValue (), wallet2 .getBaseAddress (0 ).getAddress ());
250
+ }
208
251
}
0 commit comments