writeWalletFile static method
Writes a list of AddressObject to a byte array.
Parameters:
addressList: The list of AddressObject to be written.
Returns: A List<int> representing the byte array of the written data, or null if the addressList is empty.
Implementation
static List<int>? writeWalletFile(List<AddressObject> addressList) {
List<int> bytes = [];
var nosoMath = NosoMath();
if (addressList.isEmpty) {
return null;
}
try {
for (AddressObject wallet in addressList) {
bytes.add(wallet.hash.length);
bytes.addAll(utf8.encode(wallet.hash.padRight(40)));
var custom = wallet.custom ?? "";
bytes.add(custom.length);
bytes.addAll(utf8.encode(custom.padRight(40)));
bytes.add(wallet.publicKey.length);
bytes.addAll(utf8.encode(wallet.publicKey.padRight(255)));
bytes.add(wallet.privateKey.length);
bytes.addAll(utf8.encode(wallet.privateKey.padRight(255)));
bytes.addAll(
nosoMath.intToBytes(nosoMath.doubleToBigEndian(wallet.balance)));
bytes.addAll([0, 0, 0, 0, 0, 0, 0, 0]); //Pendings
bytes.addAll([0, 0, 0, 0, 0, 0, 0, 0]); //Score
bytes.addAll([0, 0, 0, 0, 0, 0, 0, 0]); //lastOp
}
return bytes.isEmpty ? null : bytes;
} catch (e) {
print("Error writeWalletFile: $e");
return null;
}
}