Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Commit 76f25ce

Browse files
committed
Update Java code examples
1 parent 4b5ced4 commit 76f25ce

File tree

6 files changed

+47
-64
lines changed

6 files changed

+47
-64
lines changed

guides/get-started/create-account.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ import org.stellar.sdk.Server;
204204
import org.stellar.sdk.responses.AccountResponse;
205205

206206
Server server = new Server("https://horizon-testnet.stellar.org");
207-
AccountResponse account = server.accounts().account(pair);
207+
AccountResponse account = server.accounts().account(pair.getAccountId());
208208
System.out.println("Balances for account " + pair.getAccountId());
209209
for (AccountResponse.Balance balance : account.getBalances()) {
210210
System.out.println(String.format(

guides/get-started/transactions.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,10 @@ server.loadAccount(destinationId)
100100
```
101101

102102
```java
103-
Network.useTestNetwork();
104103
Server server = new Server("https://horizon-testnet.stellar.org");
105104

106105
KeyPair source = KeyPair.fromSecretSeed("SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4");
107-
KeyPair destination = KeyPair.fromAccountId("GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKSLRB6Q723BM2OARMDUYEJ5");
106+
String destination = "GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKSLRB6Q723BM2OARMDUYEJ5";
108107

109108
// First, check to make sure that the destination account exists.
110109
// You could skip this, but if the account does not exist, you will be charged
@@ -113,10 +112,10 @@ KeyPair destination = KeyPair.fromAccountId("GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKS
113112
server.accounts().account(destination);
114113

115114
// If there was no error, load up-to-date information on your account.
116-
AccountResponse sourceAccount = server.accounts().account(source);
115+
AccountResponse sourceAccount = server.accounts().account(source.getAccountId());
117116

118117
// Start building the transaction.
119-
Transaction transaction = new Transaction.Builder(sourceAccount)
118+
Transaction transaction = new Transaction.Builder(sourceAccount, Network.TESTNET)
120119
.addOperation(new PaymentOperation.Builder(destination, new AssetTypeNative(), "10").build())
121120
// A memo allows you to add your own metadata to a transaction. It's
122121
// optional and does not affect how Stellar treats the transaction.
@@ -300,7 +299,7 @@ What exactly happened there? Let’s break it down.
300299
```
301300

302301
```java
303-
AccountResponse sourceAccount = server.accounts().account(source);
302+
AccountResponse sourceAccount = server.accounts().account(source.getAccountId());
304303
```
305304

306305
```python
@@ -323,7 +322,8 @@ What exactly happened there? Let’s break it down.
323322
```
324323

325324
```java
326-
Transaction transaction = new Transaction.Builder(sourceAccount)
325+
// use Network.PUBLIC to create a transaction for the Stellar public network
326+
Transaction transaction = new Transaction.Builder(sourceAccount, Network.TESTNET)
327327
```
328328

329329
```go
@@ -544,7 +544,7 @@ function loadLastPagingToken() {
544544

545545
```java
546546
Server server = new Server("https://horizon-testnet.stellar.org");
547-
KeyPair account = KeyPair.fromAccountId("GC2BKLYOOYPDEFJKLKY6FNNRQMGFLVHJKQRGNSSRRGSMPGF32LHCQVGF");
547+
final String account = "GC2BKLYOOYPDEFJKLKY6FNNRQMGFLVHJKQRGNSSRRGSMPGF32LHCQVGF";
548548
549549
// Create an API call to query payments involving the account.
550550
PaymentsRequestBuilder paymentsRequest = server.payments().forAccount(account);
@@ -581,7 +581,7 @@ paymentsRequest.stream(new EventListener<OperationResponse>() {
581581
StringBuilder assetNameBuilder = new StringBuilder();
582582
assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getCode());
583583
assetNameBuilder.append(":");
584-
assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getIssuer().getAccountId());
584+
assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getIssuer());
585585
assetName = assetNameBuilder.toString();
586586
}
587587
@@ -590,7 +590,7 @@ paymentsRequest.stream(new EventListener<OperationResponse>() {
590590
output.append(" ");
591591
output.append(assetName);
592592
output.append(" from ");
593-
output.append(((PaymentOperationResponse) payment).getFrom().getAccountId());
593+
output.append(((PaymentOperationResponse) payment).getFrom());
594594
System.out.println(output.toString());
595595
}
596596

guides/issuing-assets.md

+14-22
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ var astroDollar = new StellarSdk.Asset(
2121
```
2222

2323
```java
24-
KeyPair issuer = StellarSdk.Keypair.fromAccountId(
25-
"GC2BKLYOOYPDEFJKLKY6FNNRQMGFLVHJKQRGNSSRRGSMPGF32LHCQVGF");
26-
Asset astroDollar = Asset.createNonNativeAsset("AstroDollar", issuer);
24+
Asset astroDollar = Asset.createNonNativeAsset("AstroDollar", "GC2BKLYOOYPDEFJKLKY6FNNRQMGFLVHJKQRGNSSRRGSMPGF32LHCQVGF");
2725
```
2826

2927
```python
@@ -123,7 +121,6 @@ server.loadAccount(receivingKeys.publicKey())
123121
```
124122

125123
```java
126-
Network.useTestNetwork();
127124
Server server = new Server("https://horizon-testnet.stellar.org");
128125

129126
// Keys for accounts to issue and receive the new asset
@@ -133,11 +130,11 @@ KeyPair receivingKeys = KeyPair
133130
.fromSecretSeed("SDSAVCRE5JRAI7UFAVLE5IMIZRD6N6WOJUWKY4GFN34LOBEEUS4W2T2D");
134131

135132
// Create an object to represent the new asset
136-
Asset astroDollar = Asset.createNonNativeAsset("AstroDollar", issuingKeys);
133+
Asset astroDollar = Asset.createNonNativeAsset("AstroDollar", issuingKeys.getAccountId());
137134

138135
// First, the receiving account must trust the asset
139-
AccountResponse receiving = server.accounts().account(receivingKeys);
140-
Transaction allowAstroDollars = new Transaction.Builder(receiving)
136+
AccountResponse receiving = server.accounts().account(receivingKeys.getAccountId());
137+
Transaction allowAstroDollars = new Transaction.Builder(receiving, Network.TESTNET)
141138
.addOperation(
142139
// The `ChangeTrust` operation creates (or alters) a trustline
143140
// The second parameter limits the amount the account can hold
@@ -147,10 +144,10 @@ allowAstroDollars.sign(receivingKeys);
147144
server.submitTransaction(allowAstroDollars);
148145

149146
// Second, the issuing account actually sends a payment using the asset
150-
AccountResponse issuing = server.accounts().account(issuingKeys);
147+
AccountResponse issuing = server.accounts().account(issuingKeys.getAccountId());
151148
Transaction sendAstroDollars = new Transaction.Builder(issuing)
152149
.addOperation(
153-
new PaymentOperation.Builder(receivingKeys, astroDollar, "10").build())
150+
new PaymentOperation.Builder(receivingKeys.getAccountId(), astroDollar, "10").build())
154151
.build();
155152
sendAstroDollars.sign(issuingKeys);
156153
server.submitTransaction(sendAstroDollars);
@@ -311,17 +308,16 @@ server.loadAccount(issuingKeys.publicKey())
311308
```
312309

313310
```java
314-
Network.useTestNetwork();
315311
Server server = new Server("https://horizon-testnet.stellar.org");
316312

317313
// Keys for issuing account
318314
KeyPair issuingKeys = KeyPair
319315
.fromSecretSeed("SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4");
320-
AccountResponse sourceAccount = server.accounts().account(issuingKeys);
316+
AccountResponse sourceAccount = server.accounts().account(issuingKeys.getAccountId());
321317

322-
Transaction setHomeDomain = new Transaction.Builder(sourceAccount)
318+
Transaction setHomeDomain = new Transaction.Builder(sourceAccount, Network.TESTNET)
323319
.addOperation(new SetOptionsOperation.Builder()
324-
.setHomeDomain("yourdomain.com").build()
320+
.setHomeDomain("yourdomain.com")
325321
.build();
326322
setHomeDomain.sign(issuingKeys);
327323
server.submitTransaction(setHomeDomain);
@@ -439,15 +435,14 @@ server
439435
```java
440436
import org.stellar.sdk.AccountFlag;
441437

442-
Network.useTestNetwork();
443438
Server server = new Server("https://horizon-testnet.stellar.org");
444439

445440
// Keys for issuing account
446441
KeyPair issuingKeys = KeyPair
447442
.fromSecretSeed("SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4");
448-
AccountResponse sourceAccount = server.accounts().account(issuingKeys);
443+
AccountResponse sourceAccount = server.accounts().account(issuingKeys.getAccountId());
449444

450-
Transaction setAuthorization = new Transaction.Builder(sourceAccount)
445+
Transaction setAuthorization = new Transaction.Builder(sourceAccount, Network.TESTNET)
451446
.addOperation(new SetOptionsOperation.Builder()
452447
.setSetFlags(
453448
AccountFlag.AUTH_REQUIRED_FLAG.getValue() |
@@ -560,14 +555,11 @@ server.loadAccount(accountId).then(function(account) {
560555

561556
```java
562557
Asset astroDollar = Asset.createNonNativeAsset(
563-
"AstroDollar",
564-
KeyPair.fromAccountId(
565-
"GC2BKLYOOYPDEFJKLKY6FNNRQMGFLVHJKQRGNSSRRGSMPGF32LHCQVGF"));
558+
"AstroDollar", "GC2BKLYOOYPDEFJKLKY6FNNRQMGFLVHJKQRGNSSRRGSMPGF32LHCQVGF"
559+
);
566560

567561
// Load the account you want to check
568-
KeyPair keysToCheck = KeyPair.fromAccountId(
569-
"GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKSLRB6Q723BM2OARMDUYEJ5");
570-
AccountResponse accountToCheck = server.accounts().account(keysToCheck);
562+
AccountResponse accountToCheck = server.accounts().account("GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKSLRB6Q723BM2OARMDUYEJ5");
571563

572564
// See if any balances are for the asset code and issuer we're looking for
573565
boolean trusted = false;

translations/pt-BR/guides/get-started/create-account.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ import org.stellar.sdk.Server;
149149
import org.stellar.sdk.responses.AccountResponse;
150150

151151
Server server = new Server("https://horizon-testnet.stellar.org");
152-
AccountResponse account = server.accounts().account(pair);
152+
AccountResponse account = server.accounts().account(pair.getAccountId());
153153
System.out.println("Saldos para conta" + pair.getAccountId());
154154
for (AccountResponse.Balance balance : account.getBalances()) {
155155
System.out.println(String.format(

translations/pt-BR/guides/get-started/transactions.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ server.loadAccount(destinationId)
7373
```
7474

7575
```java
76-
Network.useTestNetwork();
7776
Server server = new Server("https://horizon-testnet.stellar.org");
7877

7978
KeyPair source = KeyPair.fromSecretSeed("SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4");
80-
KeyPair destination = KeyPair.fromAccountId("GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKSLRB6Q723BM2OARMDUYEJ5");
79+
String destination = "GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKSLRB6Q723BM2OARMDUYEJ5";
8180

8281
// Primeiro, checar para ter certeza de que a conta de destino existe.
8382
// Você pode pular isso, mas se a conta não existir, será cobrada
@@ -86,10 +85,10 @@ KeyPair destination = KeyPair.fromAccountId("GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKS
8685
server.accounts().account(destination);
8786

8887
// Se não houver erro, carregar informações atualizadas sobre a sua conta.
89-
AccountResponse sourceAccount = server.accounts().account(source);
88+
AccountResponse sourceAccount = server.accounts().account(source.getAccountId());
9089

9190
// Começar a construir a transação.
92-
Transaction transaction = new Transaction.Builder(sourceAccount)
91+
Transaction transaction = new Transaction.Builder(sourceAccount, Network.TESTNET)
9392
.addOperation(new PaymentOperation.Builder(destination, new AssetTypeNative(), "10").build())
9493
// Um memo permite adicionar seus próprios metadados a uma transação.
9594
// É opcional e não afeta como o Stellar trata a transação.
@@ -205,7 +204,7 @@ O que exatamente aconteceu aí? Vamos ver por partes.
205204
```
206205

207206
```java
208-
AccountResponse sourceAccount = server.accounts().account(source);
207+
AccountResponse sourceAccount = server.accounts().account(source.getAccountId());
209208
```
210209

211210
</code-example>
@@ -221,7 +220,7 @@ O que exatamente aconteceu aí? Vamos ver por partes.
221220
```
222221

223222
```java
224-
Transaction transaction = new Transaction.Builder(sourceAccount)
223+
Transaction transaction = new Transaction.Builder(sourceAccount, Network.TESTNET)
225224
```
226225

227226
```go
@@ -390,7 +389,7 @@ function loadLastPagingToken() {
390389

391390
```java
392391
Server server = new Server("https://horizon-testnet.stellar.org");
393-
KeyPair account = KeyPair.fromAccountId("GC2BKLYOOYPDEFJKLKY6FNNRQMGFLVHJKQRGNSSRRGSMPGF32LHCQVGF");
392+
final String account = "GC2BKLYOOYPDEFJKLKY6FNNRQMGFLVHJKQRGNSSRRGSMPGF32LHCQVGF";
394393
395394
// Criar uma chamada de API para consultar (query) pagamentos envolvendo a conta.
396395
PaymentsRequestBuilder paymentsRequest = server.payments().forAccount(account);
@@ -427,7 +426,7 @@ paymentsRequest.stream(new EventListener<OperationResponse>() {
427426
StringBuilder assetNameBuilder = new StringBuilder();
428427
assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getCode());
429428
assetNameBuilder.append(":");
430-
assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getIssuer().getAccountId());
429+
assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getIssuer());
431430
assetName = assetNameBuilder.toString();
432431
}
433432
@@ -436,7 +435,7 @@ paymentsRequest.stream(new EventListener<OperationResponse>() {
436435
output.append(" ");
437436
output.append(assetName);
438437
output.append(" from ");
439-
output.append(((PaymentOperationResponse) payment).getFrom().getAccountId());
438+
output.append(((PaymentOperationResponse) payment).getFrom());
440439
System.out.println(output.toString());
441440
}
442441

translations/pt-BR/guides/issuing-assets.md

+14-22
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ var astroDollar = new StellarSdk.Asset(
2121
```
2222

2323
```java
24-
KeyPair issuer = StellarSdk.Keypair.fromAccountId(
25-
"GC2BKLYOOYPDEFJKLKY6FNNRQMGFLVHJKQRGNSSRRGSMPGF32LHCQVGF");
26-
Asset astroDollar = Asset.createNonNativeAsset("AstroDollar", issuer);
24+
Asset astroDollar = Asset.createNonNativeAsset("AstroDollar", "GC2BKLYOOYPDEFJKLKY6FNNRQMGFLVHJKQRGNSSRRGSMPGF32LHCQVGF");
2725
```
2826

2927
```json
@@ -106,7 +104,6 @@ server.loadAccount(receivingKeys.publicKey())
106104
```
107105

108106
```java
109-
Network.useTestNetwork();
110107
Server server = new Server("https://horizon-testnet.stellar.org");
111108

112109
// Chaves para contas emitirem e receberem o novo ativo
@@ -116,11 +113,11 @@ KeyPair receivingKeys = KeyPair
116113
.fromSecretSeed("SDSAVCRE5JRAI7UFAVLE5IMIZRD6N6WOJUWKY4GFN34LOBEEUS4W2T2D");
117114

118115
// Criar um objeto para representar o novo ativo
119-
Asset astroDollar = Asset.createNonNativeAsset("AstroDollar", issuingKeys);
116+
Asset astroDollar = Asset.createNonNativeAsset("AstroDollar", issuingKeys.getAccountId());
120117

121118
// Primeiro, a conta recipiente deve confiar no ativo
122-
AccountResponse receiving = server.accounts().account(receivingKeys);
123-
Transaction allowAstroDollars = new Transaction.Builder(receiving)
119+
AccountResponse receiving = server.accounts().account(receivingKeys.getAccountId());
120+
Transaction allowAstroDollars = new Transaction.Builder(receiving, Network.TESTNET)
124121
.addOperation(
125122
// A operação `ChangeTrust` cria (ou altera) uma trustline
126123
// O segundo parâmetro limita a quantidade que a conta pode manter
@@ -130,10 +127,10 @@ allowAstroDollars.sign(receivingKeys);
130127
server.submitTransaction(allowAstroDollars);
131128

132129
// Depois, a conta emissora de fato envia um pagamento usando o ativo
133-
AccountResponse issuing = server.accounts().account(issuingKeys);
130+
AccountResponse issuing = server.accounts().account(issuingKeys.getAccountId());
134131
Transaction sendAstroDollars = new Transaction.Builder(issuing)
135132
.addOperation(
136-
new PaymentOperation.Builder(receivingKeys, astroDollar, "10").build())
133+
new PaymentOperation.Builder(receivingKeys.getAccountId(), astroDollar, "10").build())
137134
.build();
138135
sendAstroDollars.sign(issuingKeys);
139136
server.submitTransaction(sendAstroDollars);
@@ -233,17 +230,16 @@ server.loadAccount(issuingKeys.publicKey())
233230
```
234231

235232
```java
236-
Network.useTestNetwork();
237233
Server server = new Server("https://horizon-testnet.stellar.org");
238234

239235
// Chaves para a conta emissora
240236
KeyPair issuingKeys = KeyPair
241237
.fromSecretSeed("SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4");
242-
AccountResponse sourceAccount = server.accounts().account(issuingKeys);
238+
AccountResponse sourceAccount = server.accounts().account(issuingKeys.getAccountId());
243239

244-
Transaction setHomeDomain = new Transaction.Builder(sourceAccount)
240+
Transaction setHomeDomain = new Transaction.Builder(sourceAccount, Network.TESTNET)
245241
.addOperation(new SetOptionsOperation.Builder()
246-
.setHomeDomain("seudominio.com").build()
242+
.setHomeDomain("yourdomain.com")
247243
.build();
248244
setAuthorization.sign(issuingKeys);
249245
server.submitTransaction(setHomeDomain);
@@ -291,15 +287,14 @@ server.submitTransaction(transaction);
291287
```java
292288
import org.stellar.sdk.AccountFlag;
293289

294-
Network.useTestNetwork();
295290
Server server = new Server("https://horizon-testnet.stellar.org");
296291

297292
// Chaves para a conta emissora
298293
KeyPair issuingKeys = KeyPair
299294
.fromSecretSeed("SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4");
300-
AccountResponse sourceAccount = server.accounts().account(issuingKeys);
295+
AccountResponse sourceAccount = server.accounts().account(issuingKeys.getAccountId());
301296

302-
Transaction setAuthorization = new Transaction.Builder(sourceAccount)
297+
Transaction setAuthorization = new Transaction.Builder(sourceAccount, Network.TESTNET)
303298
.addOperation(new SetOptionsOperation.Builder()
304299
.setSetFlags(
305300
AccountFlag.AUTH_REQUIRED_FLAG.getValue() |
@@ -337,14 +332,11 @@ server.loadAccount(accountId).then(function(account) {
337332

338333
```java
339334
Asset astroDollar = Asset.createNonNativeAsset(
340-
"AstroDollar",
341-
KeyPair.fromAccountId(
342-
"GC2BKLYOOYPDEFJKLKY6FNNRQMGFLVHJKQRGNSSRRGSMPGF32LHCQVGF"));
335+
"AstroDollar", "GC2BKLYOOYPDEFJKLKY6FNNRQMGFLVHJKQRGNSSRRGSMPGF32LHCQVGF"
336+
);
343337

344338
// Carregar a conta que se quer verificar
345-
KeyPair keysToCheck = KeyPair.fromAccountId(
346-
"GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKSLRB6Q723BM2OARMDUYEJ5");
347-
AccountResponse accountToCheck = server.accounts().account(keysToCheck);
339+
AccountResponse accountToCheck = server.accounts().account("GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKSLRB6Q723BM2OARMDUYEJ5");
348340

349341
// Ver se há saldos referentes ao código do ativo e emissora que estamos procurando
350342
boolean trusted = false;

0 commit comments

Comments
 (0)