-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
149 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
sample/android/src/main/java/xyz/mcxross/ksui/android/controller/Transaction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package xyz.mcxross.ksui.android.controller | ||
|
||
import android.util.Log | ||
import xyz.mcxross.ksui.client.EndPoint | ||
import xyz.mcxross.ksui.client.suiHttpClient | ||
import xyz.mcxross.ksui.extension.asObjectReference | ||
import xyz.mcxross.ksui.model.Argument | ||
import xyz.mcxross.ksui.model.IntentMessage | ||
import xyz.mcxross.ksui.model.IntentType | ||
import xyz.mcxross.ksui.model.SuiAddress | ||
import xyz.mcxross.ksui.model.TransactionDataComposer | ||
import xyz.mcxross.ksui.model.programmableTx | ||
import xyz.mcxross.ksui.util.bcs | ||
import xyz.mcxross.ksui.util.fullTxBlockResponseOptions | ||
import xyz.mcxross.ksui.util.inputs | ||
import xyz.mcxross.sc.SuiCommons | ||
|
||
suspend fun send(sk: String, from: SuiAddress, toSuiAddress: SuiAddress) { | ||
val suiRpcClient = suiHttpClient { | ||
endpoint = EndPoint.DEVNET | ||
agentName = "KSUI/0.0.1" | ||
maxRetries = 10 | ||
} | ||
|
||
val paymentObject = suiRpcClient.getCoins(SuiAddress(from.pubKey), limit = 5) | ||
|
||
Log.d("MainActivity", paymentObject.data.map { it.asObjectReference() }.toString()) | ||
|
||
val gasPrice = suiRpcClient.getReferenceGasPrice() | ||
|
||
Log.d("MainActivity", "Reference Gas Price: $gasPrice") | ||
|
||
val pt = programmableTx { | ||
command { | ||
val splitCoins = splitCoins { | ||
coin = Argument.GasCoin | ||
into = inputs(1_000.toULong()) | ||
} | ||
|
||
/*transferObjects { | ||
objects = inputs(splitCoins) | ||
to = input(toSuiAddress.pubKey) | ||
}*/ | ||
} | ||
} | ||
|
||
val txData = | ||
TransactionDataComposer.programmable( | ||
from, | ||
listOf(paymentObject.data[0].asObjectReference()), | ||
pt, | ||
5_000_000UL, | ||
gasPrice.cost.toULong(), | ||
) | ||
|
||
val intentMessage = IntentMessage(IntentType.SUI_TX.intent(), txData) | ||
|
||
val sig = SuiCommons.utils.suiSign(bcs(intentMessage), sk) | ||
|
||
Log.d("MainActivity", "Signature: $sig") | ||
|
||
Log.d("MainActivity", "Sending transaction") | ||
|
||
val result = | ||
suiRpcClient.executeTransactionBlock( | ||
SuiCommons.encode.encodeBase64(bcs(intentMessage)), | ||
listOf(sig), | ||
fullTxBlockResponseOptions(), | ||
) | ||
|
||
Log.d("MainActivity", "Transaction result: $result") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 41 additions & 2 deletions
43
sample/android/src/main/java/xyz/mcxross/ksui/android/ui/view/Wallet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,54 @@ | ||
package xyz.mcxross.ksui.android.ui.view | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextField | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun Wallet(modifier: Modifier = Modifier, onNewWallet: () -> Unit) { | ||
fun Wallet( | ||
modifier: Modifier = Modifier, | ||
onImportWallet: (String) -> Unit, | ||
onNewWallet: () -> Unit, | ||
) { | ||
var importing by remember { mutableStateOf(false) } | ||
var importString by remember { mutableStateOf("") } | ||
Box(modifier = modifier, contentAlignment = Alignment.Center) { | ||
Button(onClick = onNewWallet) { Text("Create Wallet") } | ||
Column { | ||
if (!importing) { | ||
Button(modifier = Modifier.padding(8.dp).fillMaxWidth(), onClick = onNewWallet) { | ||
Text("Create Wallet") | ||
} | ||
} else { | ||
TextField( | ||
modifier = Modifier.fillMaxWidth(), | ||
value = importString, | ||
label = { Text("Enter Phrase or Private Key") }, | ||
onValueChange = { importString = it }, | ||
) | ||
} | ||
Button( | ||
modifier = Modifier.padding(8.dp).fillMaxWidth(), | ||
onClick = { | ||
if (importing) { | ||
onImportWallet(importString) | ||
} | ||
importing = true | ||
}, | ||
) { | ||
Text("Import Wallet") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters