-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up creating and sending transactions (#55)
- Loading branch information
Showing
20 changed files
with
1,039 additions
and
220 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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,73 @@ | ||
import { StatusBar } from "expo-status-bar"; | ||
import { Button, ScrollView, StyleSheet, Text, View } from "react-native"; | ||
import { Network } from "../../../data/constants"; | ||
import { wallet } from "../../../data/wallet/wallet"; | ||
import * as Uint8ArrayUtils from "../../../utils/uint8Array"; | ||
import { useState } from "react"; | ||
|
||
export default function MenuDebugPending() { | ||
const [transactions, setTransactions] = useState< | ||
{ | ||
hash: Uint8Array; | ||
}[] | ||
>(); | ||
|
||
const refreshTransactions = async () => { | ||
if (wallet.state.type !== "STARTED") { | ||
return; | ||
} | ||
const account = await wallet.getActiveAccountWithHeadAndBalances( | ||
Network.TESTNET, | ||
); | ||
if (!account) { | ||
return; | ||
} | ||
const txns = await wallet.state.db.getPendingTransactions( | ||
account.id, | ||
Network.TESTNET, | ||
); | ||
console.log(`txns: ${txns.length}`); | ||
|
||
setTransactions(txns); | ||
}; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<View> | ||
<Button | ||
onPress={async () => { | ||
await refreshTransactions(); | ||
}} | ||
title="Get Pending Transactions" | ||
/> | ||
</View> | ||
<ScrollView> | ||
{transactions?.map((txn, i) => ( | ||
<View key={i} style={{ marginVertical: 5 }}> | ||
<Text>{Uint8ArrayUtils.toHex(txn.hash)}</Text> | ||
<Button | ||
onPress={async () => { | ||
if (wallet.state.type !== "STARTED") { | ||
return; | ||
} | ||
await wallet.state.db.removePendingTransaction(txn.hash); | ||
await refreshTransactions(); | ||
}} | ||
title="Delete" | ||
/> | ||
</View> | ||
))} | ||
</ScrollView> | ||
<StatusBar style="auto" /> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: "#fff", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
}, | ||
}); |
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,99 @@ | ||
import { StatusBar } from "expo-status-bar"; | ||
import { Button, ScrollView, StyleSheet, Text, View } from "react-native"; | ||
import { Network } from "../../../data/constants"; | ||
import { wallet } from "../../../data/wallet/wallet"; | ||
import { Blockchain } from "../../../data/blockchain"; | ||
import * as Uint8ArrayUtils from "../../../utils/uint8Array"; | ||
import { useState } from "react"; | ||
|
||
export default function MenuDebugUnspentNotes() { | ||
const [notes, setNotes] = useState< | ||
{ | ||
assetId: Uint8Array; | ||
value: string; | ||
}[] | ||
>(); | ||
|
||
const [balances, setBalances] = useState< | ||
{ | ||
assetId: Uint8Array; | ||
confirmed: string; | ||
unconfirmed: string; | ||
pending: string; | ||
available: string; | ||
}[] | ||
>(); | ||
|
||
const sum = | ||
notes?.reduce((prev, cur) => { | ||
console.log(BigInt(cur.value).toString()); | ||
return prev + BigInt(cur.value); | ||
}, BigInt(0)) ?? BigInt(0); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<View> | ||
<Button | ||
onPress={async () => { | ||
if (wallet.state.type !== "STARTED") { | ||
return; | ||
} | ||
const account = await wallet.getActiveAccountWithHeadAndBalances( | ||
Network.TESTNET, | ||
); | ||
if (!account) { | ||
return; | ||
} | ||
setBalances(account.balances); | ||
const seq = await Blockchain.getLatestBlock(Network.TESTNET); | ||
const notes = await wallet.state.db.getUnspentNotes( | ||
seq.sequence, | ||
2, | ||
account?.id, | ||
Uint8ArrayUtils.fromHex( | ||
"51f33a2f14f92735e562dc658a5639279ddca3d5079a6d1242b2a588a9cbf44c", | ||
), | ||
Network.TESTNET, | ||
); | ||
setNotes(notes); | ||
}} | ||
title="Get Notes" | ||
/> | ||
</View> | ||
<View> | ||
{balances?.map((balance, i) => ( | ||
<View key={i}> | ||
<Text>{Uint8ArrayUtils.toHex(balance.assetId)}</Text> | ||
<Text>Confirmed: {balance.confirmed}</Text> | ||
<Text>Unconfirmed: {balance.unconfirmed}</Text> | ||
<Text>Pending: {balance.pending}</Text> | ||
<Text>Available: {balance.available}</Text> | ||
</View> | ||
))} | ||
{notes && ( | ||
<Text> | ||
Total: {sum.toString()} ({notes?.length ?? 0} notes) | ||
</Text> | ||
)} | ||
</View> | ||
<ScrollView> | ||
{notes?.map((note, i) => ( | ||
<View key={i} style={{ marginVertical: 5 }}> | ||
<Text>{note.value}</Text> | ||
<Text>{Uint8ArrayUtils.toHex(note.assetId)}</Text> | ||
</View> | ||
))} | ||
</ScrollView> | ||
<StatusBar style="auto" /> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: "#fff", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
}, | ||
}); |
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
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
Oops, something went wrong.