-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquest5.kt
77 lines (66 loc) · 2.44 KB
/
quest5.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package set3
import Keys
import friendBot
import org.stellar.sdk.*
fun main() {
val server = Server("https://horizon-testnet.stellar.org")
val questAccountKeys = KeyPair.fromSecretSeed(Keys.set3q5Key)
val helperAccountKeys = KeyPair.fromSecretSeed(Keys.set3helperKey)
// Ask friendbot to fund our accounts
helperAccountKeys.friendBot()
questAccountKeys.friendBot()
val questAccount = server.accounts().account(questAccountKeys.accountId)
val txBuilder = Transaction.Builder(questAccount, Network.TESTNET)
.setBaseFee(FeeBumpTransaction.MIN_BASE_FEE)
.setTimeout(180)
val asset = Asset.createNonNativeAsset("MariusLenk", questAccountKeys.accountId)
// enable clawback for issuer account
// 2: authorization revocable, 8: clawback enabled
txBuilder.addOperation(
SetOptionsOperation.Builder()
.setSetFlags(2 or 8)
.build()
)
// establish trustline from helper to issuer
txBuilder.addOperation(
ChangeTrustOperation.Builder(asset, "1000000")
.setSourceAccount(helperAccountKeys.accountId)
.build()
)
// send asset to helper
txBuilder.addOperation(
PaymentOperation.Builder(helperAccountKeys.accountId, asset, "1000").build()
)
val createAssetTx = txBuilder.build()
createAssetTx.sign(questAccountKeys)
createAssetTx.sign(helperAccountKeys)
println("Executing tx.. (sending asset)")
try {
val response = server.submitTransaction(createAssetTx)
println("Success!")
println("txHash: ${response.hash}")
println("result: ${response.resultXdr.get()}")
} catch (e: Exception) {
println("Something went wrong!")
println(e.message)
}
val tx2Builder = Transaction.Builder(questAccount, Network.TESTNET)
.setBaseFee(FeeBumpTransaction.MIN_BASE_FEE)
.setTimeout(180)
// now claw back the 1000
tx2Builder.addOperation(
ClawbackOperation.Builder(helperAccountKeys.accountId, asset, "1000").build()
)
val clawbackTx = tx2Builder.build()
clawbackTx.sign(questAccountKeys)
println("Executing tx.. (clawback asset)")
try {
val response = server.submitTransaction(clawbackTx)
println("Success!")
println("txHash: ${response.hash}")
println("result: ${response.resultXdr.get()}")
} catch (e: Exception) {
println("Something went wrong!")
println(e.message)
}
}