Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/common/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TransactionHelper {
//无 nonce、有 remark(成块补零)
static const int padZerosNoNonceHasRemark = 18;

static String getTransaction(String fromAddress, String toAddress, String remark, double value, bip32.BIP32 wallet, String nonce) {
static String getTransaction(String fromAddress, String toAddress, String remark, double value, bip32.BIP32 wallet, String nonce, double fee) {
// print('getTransaction: $fromAddress, $toAddress, $remark, $value, $nonce');
bool isPubKeyEven = wallet.publicKey[0] % 2 == 0;
String from = checkBase58Address(fromAddress);
Expand Down Expand Up @@ -71,7 +71,8 @@ class TransactionHelper {
}
sb += HEX.encode(timeBytes.buffer.asUint8List());

sb += "0000000000000000";
// 添加可变手续费
sb += fee2Bytes(fee);
// print('header: $sb');
// nonce:前面补 48 个 0
// 由于rpc查询出来的nonce(rpc查出来的到的结果是String类型),会放在该32字节的后八个字段,然后前面24个字节的零,这后八个字节存放nonce的方式是小端序存放。
Expand Down Expand Up @@ -146,6 +147,19 @@ class TransactionHelper {
return res + amount;
}

static String fee2Bytes(double fee) {
final amountValue = (fee * 1000000000).round();

final valBytes = Uint8List(8);
ByteData.view(valBytes.buffer).setUint64(0, amountValue, Endian.little);

final hexString = valBytes.map((byte) {
return byte.toRadixString(16).padLeft(2, '0');
}).join();

return hexString;
}

static Int64 getCurrentTimestamp() {
var t0 = DateTime.now().toUtc().millisecondsSinceEpoch * 1000000;
Int64 t = Int64(t0);
Expand Down
5 changes: 3 additions & 2 deletions lib/desktop/desktop_transaction_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class DesktopTransactionDetailPageWidgetState extends State<DesktopTransactionDe
Transaction transaction = widget.transaction;
String address = widget.address;
bool isSend = transaction.from == address;
String displayFee = fee.isNotEmpty ? fee : Helper.removeTrailingZeros((transaction.fee + 0.1).toString());
ContactsModal contacts = Provider.of<ContactsModal>(context);
ContactsItem otherContact = contacts.contactsList.firstWhere((element) => element.address == otherAddress, orElse: () => ContactsItem("", otherAddress));
return DesktopModalFrame(
Expand Down Expand Up @@ -162,7 +163,7 @@ class DesktopTransactionDetailPageWidgetState extends State<DesktopTransactionDe
Helper.showToast(context, AppLocalizations.of(context)!.copied_to_clipboard);
}),
const SizedBox(height: 1),
TransactionButton(showCopy: false, title: AppLocalizations.of(context)!.fee, value: '$fee XDAG', borderRadius: transaction.remark.isNotEmpty ? BorderRadius.zero : const BorderRadius.only(bottomLeft: Radius.circular(8), bottomRight: Radius.circular(8))),
TransactionButton(showCopy: false, title: AppLocalizations.of(context)!.fee, value: '$displayFee XDAG', borderRadius: transaction.remark.isNotEmpty ? BorderRadius.zero : const BorderRadius.only(bottomLeft: Radius.circular(8), bottomRight: Radius.circular(8))),
const SizedBox(height: 1),
if (transaction.remark.isNotEmpty)
TransactionButton(
Expand Down Expand Up @@ -233,7 +234,7 @@ class DesktopTransactionDetail extends StatelessWidget {
value: transaction.from,
),
const SizedBox(height: 1),
TransactionButton(showCopy: false, title: AppLocalizations.of(context)!.fee, value: '0.00 XDAG', borderRadius: transaction.remark.isNotEmpty ? BorderRadius.zero : const BorderRadius.only(bottomLeft: Radius.circular(8), bottomRight: Radius.circular(8))),
TransactionButton(showCopy: false, title: AppLocalizations.of(context)!.fee, value: '${transaction.fee + 0.1} XDAG', borderRadius: transaction.remark.isNotEmpty ? BorderRadius.zero : const BorderRadius.only(bottomLeft: Radius.circular(8), bottomRight: Radius.circular(8))),
const SizedBox(height: 1),
if (transaction.remark.isNotEmpty)
TransactionButton(
Expand Down
Loading