mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-11 05:04:35 +00:00
fix for open blocks + fix for new wallet creation
This commit is contained in:
parent
c5f2480634
commit
e0efbe669d
1 changed files with 42 additions and 24 deletions
|
@ -31,6 +31,8 @@ import 'dart:async';
|
||||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||||
|
|
||||||
const int MINIMUM_CONFIRMATIONS = 1;
|
const int MINIMUM_CONFIRMATIONS = 1;
|
||||||
|
const String DEFAULT_REPRESENTATIVE =
|
||||||
|
"nano_38713x95zyjsqzx6nm1dsom1jmm668owkeb9913ax6nfgj15az3nu8xkx579";
|
||||||
|
|
||||||
class NanoWallet extends CoinServiceAPI
|
class NanoWallet extends CoinServiceAPI
|
||||||
with WalletCache, WalletDB, CoinControlInterface {
|
with WalletCache, WalletDB, CoinControlInterface {
|
||||||
|
@ -135,7 +137,7 @@ class NanoWallet extends CoinServiceAPI
|
||||||
Future<String?> requestWork(String hash) async {
|
Future<String?> requestWork(String hash) async {
|
||||||
return http
|
return http
|
||||||
.post(
|
.post(
|
||||||
Uri.parse("https://rpc.nano.to"),
|
Uri.parse("https://rpc.nano.to"), // this should be a
|
||||||
headers: {'Content-type': 'application/json'},
|
headers: {'Content-type': 'application/json'},
|
||||||
body: json.encode(
|
body: json.encode(
|
||||||
{
|
{
|
||||||
|
@ -295,8 +297,7 @@ class NanoWallet extends CoinServiceAPI
|
||||||
final data = jsonDecode(response.body);
|
final data = jsonDecode(response.body);
|
||||||
_balance = Balance(
|
_balance = Balance(
|
||||||
total: Amount(
|
total: Amount(
|
||||||
rawValue: (BigInt.parse(data["balance"]
|
rawValue: (BigInt.parse(data["balance"].toString())) ~/
|
||||||
.toString()) /*+ BigInt.parse(data["receivable"].toString())*/) ~/
|
|
||||||
BigInt.from(10).pow(23),
|
BigInt.from(10).pow(23),
|
||||||
fractionDigits: 7),
|
fractionDigits: 7),
|
||||||
spendable: Amount(
|
spendable: Amount(
|
||||||
|
@ -317,17 +318,38 @@ class NanoWallet extends CoinServiceAPI
|
||||||
// TODO: the opening block of an account is a special case
|
// TODO: the opening block of an account is a special case
|
||||||
bool openBlock = false;
|
bool openBlock = false;
|
||||||
|
|
||||||
|
final headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
};
|
||||||
|
|
||||||
// our address:
|
// our address:
|
||||||
final String publicAddress = await getAddressFromMnemonic();
|
final String publicAddress = await getAddressFromMnemonic();
|
||||||
|
|
||||||
|
// first check if the account is open:
|
||||||
|
// get the account info (we need the frontier and representative):
|
||||||
|
final infoBody = jsonEncode({
|
||||||
|
"action": "account_info",
|
||||||
|
"representative": "true",
|
||||||
|
"account": publicAddress,
|
||||||
|
});
|
||||||
|
final infoResponse = await http.post(
|
||||||
|
Uri.parse(getCurrentNode().host),
|
||||||
|
headers: headers,
|
||||||
|
body: infoBody,
|
||||||
|
);
|
||||||
|
final infoData = jsonDecode(infoResponse.body);
|
||||||
|
|
||||||
|
if (infoData["error"] != null) {
|
||||||
|
// account is not open yet, we need to create an open block:
|
||||||
|
openBlock = true;
|
||||||
|
}
|
||||||
|
|
||||||
// first get the account balance:
|
// first get the account balance:
|
||||||
final balanceBody = jsonEncode({
|
final balanceBody = jsonEncode({
|
||||||
"action": "account_balance",
|
"action": "account_balance",
|
||||||
"account": publicAddress,
|
"account": publicAddress,
|
||||||
});
|
});
|
||||||
final headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
};
|
|
||||||
final balanceResponse = await http.post(
|
final balanceResponse = await http.post(
|
||||||
Uri.parse(getCurrentNode().host),
|
Uri.parse(getCurrentNode().host),
|
||||||
headers: headers,
|
headers: headers,
|
||||||
|
@ -340,21 +362,13 @@ class NanoWallet extends CoinServiceAPI
|
||||||
final BigInt txAmount = BigInt.parse(amountRaw);
|
final BigInt txAmount = BigInt.parse(amountRaw);
|
||||||
final BigInt balanceAfterTx = currentBalance + txAmount;
|
final BigInt balanceAfterTx = currentBalance + txAmount;
|
||||||
|
|
||||||
// get the account info (we need the frontier and representative):
|
String frontier = infoData["frontier"].toString();
|
||||||
final infoBody = jsonEncode({
|
String representative = infoData["representative"].toString();
|
||||||
"action": "account_info",
|
|
||||||
"representative": "true",
|
|
||||||
"account": publicAddress,
|
|
||||||
});
|
|
||||||
final infoResponse = await http.post(
|
|
||||||
Uri.parse(getCurrentNode().host),
|
|
||||||
headers: headers,
|
|
||||||
body: infoBody,
|
|
||||||
);
|
|
||||||
|
|
||||||
String frontier = jsonDecode(infoResponse.body)["frontier"].toString();
|
if (openBlock) {
|
||||||
final String representative =
|
// we don't have a representative set yet:
|
||||||
jsonDecode(infoResponse.body)["representative"].toString();
|
representative = DEFAULT_REPRESENTATIVE;
|
||||||
|
}
|
||||||
|
|
||||||
// link = send block hash:
|
// link = send block hash:
|
||||||
final String link = blockHash;
|
final String link = blockHash;
|
||||||
|
@ -495,7 +509,12 @@ class NanoWallet extends CoinServiceAPI
|
||||||
nonce: 0);
|
nonce: 0);
|
||||||
transactionList.add(transaction);
|
transactionList.add(transaction);
|
||||||
}
|
}
|
||||||
await db.putTransactions(transactionList);
|
try {
|
||||||
|
await db.putTransactions(transactionList);
|
||||||
|
} catch (e) {
|
||||||
|
// I don't know why this fails sometimes, but it does
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -552,7 +571,7 @@ class NanoWallet extends CoinServiceAPI
|
||||||
value: publicAddress,
|
value: publicAddress,
|
||||||
publicKey: [], // TODO: add public key
|
publicKey: [], // TODO: add public key
|
||||||
derivationIndex: 0,
|
derivationIndex: 0,
|
||||||
derivationPath: DerivationPath(),
|
derivationPath: null,
|
||||||
type: AddressType.unknown,
|
type: AddressType.unknown,
|
||||||
subType: AddressSubType.receiving,
|
subType: AddressSubType.receiving,
|
||||||
);
|
);
|
||||||
|
@ -650,8 +669,7 @@ class NanoWallet extends CoinServiceAPI
|
||||||
value: publicAddress,
|
value: publicAddress,
|
||||||
publicKey: [], // TODO: add public key
|
publicKey: [], // TODO: add public key
|
||||||
derivationIndex: 0,
|
derivationIndex: 0,
|
||||||
derivationPath: DerivationPath()
|
derivationPath: null,
|
||||||
..value = "0/0", // TODO: Check if this is true
|
|
||||||
type: AddressType.unknown,
|
type: AddressType.unknown,
|
||||||
subType: AddressSubType.receiving,
|
subType: AddressSubType.receiving,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue