...
This commit is contained in:
@@ -135,13 +135,13 @@ pub mut:
|
||||
pub fn (self AccountAsset) dump(mut e encoder.Encoder) ! {
|
||||
e.add_u32(self.assetid)
|
||||
e.add_f64(self.balance)
|
||||
e.add_map_string_string(self.metadata)
|
||||
e.add_map_string(self.metadata)
|
||||
}
|
||||
|
||||
fn (mut self AccountAsset) load(mut e encoder.Decoder) ! {
|
||||
self.assetid = e.get_u32()!
|
||||
self.balance = e.get_f64()!
|
||||
self.metadata = e.get_map_string_string()!
|
||||
self.metadata = e.get_map_string()!
|
||||
}
|
||||
|
||||
pub struct DBAccount {
|
||||
|
||||
@@ -99,7 +99,7 @@ pub fn (mut self DBSignature) new(args SignatureArg) !Signature {
|
||||
signer_id: args.signer_id
|
||||
tx_id: args.tx_id
|
||||
signature: args.signature
|
||||
timestamp: ourtime.now().unix()
|
||||
timestamp: u64(ourtime.now().unix())
|
||||
}
|
||||
|
||||
o.name = args.name
|
||||
@@ -130,4 +130,4 @@ pub fn (mut self DBSignature) get(id u32) !Signature {
|
||||
|
||||
pub fn (mut self DBSignature) list() ![]Signature {
|
||||
return self.db.list[Signature]()!.map(self.get(it)!)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,23 @@ import freeflowuniverse.herolib.data.encoder
|
||||
import freeflowuniverse.herolib.data.ourtime
|
||||
import freeflowuniverse.herolib.hero.db
|
||||
|
||||
// Transaction represents a financial transaction
|
||||
@[heap]
|
||||
pub struct Transaction {
|
||||
db.Base
|
||||
pub mut:
|
||||
txid u32
|
||||
source u32
|
||||
destination u32
|
||||
assetid u32
|
||||
amount f64
|
||||
timestamp u64
|
||||
status string
|
||||
memo string
|
||||
tx_type TransactionType
|
||||
signatures []TransactionSignature
|
||||
}
|
||||
|
||||
// TransactionType represents the type of transaction
|
||||
pub enum TransactionType {
|
||||
transfer
|
||||
@@ -23,23 +40,6 @@ pub mut:
|
||||
timestamp u64
|
||||
}
|
||||
|
||||
// Transaction represents a financial transaction
|
||||
@[heap]
|
||||
pub struct Transaction {
|
||||
db.Base
|
||||
pub mut:
|
||||
txid u32
|
||||
source u32
|
||||
destination u32
|
||||
assetid u32
|
||||
amount f64
|
||||
timestamp u64
|
||||
status string
|
||||
memo string
|
||||
tx_type TransactionType
|
||||
signatures []TransactionSignature
|
||||
}
|
||||
|
||||
pub struct DBTransaction {
|
||||
pub mut:
|
||||
db &db.DB @[skip; str: skip]
|
||||
@@ -105,7 +105,7 @@ pub fn (self Transaction) dump(mut e encoder.Encoder) ! {
|
||||
e.add_string(self.status)
|
||||
e.add_string(self.memo)
|
||||
e.add_int(int(self.tx_type))
|
||||
|
||||
|
||||
// signatures
|
||||
e.add_int(self.signatures.len)
|
||||
for sig in self.signatures {
|
||||
@@ -124,8 +124,8 @@ fn (mut self DBTransaction) load(mut o Transaction, mut e encoder.Decoder) ! {
|
||||
o.timestamp = e.get_u64()!
|
||||
o.status = e.get_string()!
|
||||
o.memo = e.get_string()!
|
||||
o.tx_type = TransactionType(e.get_int()!)
|
||||
|
||||
o.tx_type = unsafe { TransactionType(e.get_int()!) }
|
||||
|
||||
// signatures
|
||||
sig_len := e.get_int()!
|
||||
o.signatures = []TransactionSignature{cap: sig_len}
|
||||
@@ -198,4 +198,4 @@ pub fn (mut self DBTransaction) get(id u32) !Transaction {
|
||||
|
||||
pub fn (mut self DBTransaction) list() ![]Transaction {
|
||||
return self.db.list[Transaction]()!.map(self.get(it)!)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user