Skip to content

Commit

Permalink
Improve SEP-24 example (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifropc authored Jul 12, 2023
1 parent e6f9358 commit cf6ab20
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions examples/SEP-24/src/main/kotlin/org/stellar/example/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,34 @@ suspend fun main() {
)

// Send transaction with transfer
val t = (statusChange.transaction as WithdrawalTransaction)
val transfer = stellar.transaction(keypair).transferWithdrawalTransaction(t, asset).build()
val anchorTransaction = (statusChange.transaction as WithdrawalTransaction)
val transfer = stellar.transaction(keypair).transferWithdrawalTransaction(anchorTransaction, asset).build()

transfer.sign(keypair)

stellar.submitTransaction(transfer)

var terminalStatus: TransactionStatus? = null

do {
statusChange = withdrawalWatcher.channel.receive()

when (statusChange) {
is StatusChange ->
println(
"Withdrawal transaction status changed to ${statusChange.status}. " +
"Message: ${statusChange.transaction.message}"
)
is StatusChange -> {
if (statusChange.status.isTerminal()) {
terminalStatus = statusChange.status
}
}
is ChannelClosed -> println("Transaction tracking finished")
is ExceptionHandlerExit ->
println("Retries exhausted trying obtain transaction data, giving up.")
}
} while (statusChange !is ChannelClosed)

if (terminalStatus != TransactionStatus.COMPLETED) {
println("Transaction was not completed")
}

println("Successful withdrawal")

wallet.close()
Expand Down

0 comments on commit cf6ab20

Please sign in to comment.