|
|
@@ -153,7 +153,7 @@ impl WalletDb {
|
|
|
debug!("Returning default keypair");
|
|
|
let mut conn = self.conn.acquire().await?;
|
|
|
|
|
|
- let is_default: u32 = 1;
|
|
|
+ let is_default = 1;
|
|
|
|
|
|
let row = sqlx::query("SELECT * FROM keys WHERE is_default = ?1;")
|
|
|
.bind(is_default)
|
|
|
@@ -267,11 +267,10 @@ impl WalletDb {
|
|
|
let serial = deserialize(row.get("serial"))?;
|
|
|
let coin_blind = deserialize(row.get("coin_blind"))?;
|
|
|
let value_blind = deserialize(row.get("valcom_blind"))?;
|
|
|
- // TODO: FIXME:
|
|
|
- let value_bytes: Vec<u8> = row.get("value");
|
|
|
- let value = u64::from_le_bytes(value_bytes.try_into().unwrap());
|
|
|
+ let value = deserialize(row.get("value"))?;
|
|
|
let token_id = deserialize(row.get("drk_address"))?;
|
|
|
- let note = Note { serial, value, token_id, coin_blind, value_blind };
|
|
|
+ let token_blind = deserialize(row.get("token_blind"))?;
|
|
|
+ let note = Note { serial, value, token_id, coin_blind, value_blind, token_blind };
|
|
|
|
|
|
let secret = deserialize(row.get("secret"))?;
|
|
|
let nullifier = deserialize(row.get("nullifier"))?;
|
|
|
@@ -296,14 +295,16 @@ impl WalletDb {
|
|
|
let serial = serialize(&own_coin.note.serial);
|
|
|
let coin_blind = serialize(&own_coin.note.coin_blind);
|
|
|
let value_blind = serialize(&own_coin.note.value_blind);
|
|
|
- let value = own_coin.note.value.to_le_bytes();
|
|
|
+ let token_blind = serialize(&own_coin.note.token_blind);
|
|
|
+ let value = serialize(&own_coin.note.value);
|
|
|
let drk_address = serialize(&own_coin.note.token_id);
|
|
|
let secret = serialize(&own_coin.secret);
|
|
|
let nullifier = serialize(&own_coin.nullifier);
|
|
|
let leaf_position = serialize(&own_coin.leaf_position);
|
|
|
- let is_spent: u32 = 0;
|
|
|
+ let is_spent: u8 = 0;
|
|
|
|
|
|
let token_id_enc = bs58::encode(&own_coin.note.token_id.to_repr()).into_string();
|
|
|
+
|
|
|
let (network, net_address) =
|
|
|
if let Some((network, token_info)) = tokenlist.by_addr.get(&token_id_enc) {
|
|
|
(network, token_info.net_address.clone())
|
|
|
@@ -312,21 +313,24 @@ impl WalletDb {
|
|
|
(&NetworkName::DarkFi, "unknown".to_string())
|
|
|
};
|
|
|
|
|
|
+ let network = serialize(network);
|
|
|
+
|
|
|
let mut conn = self.conn.acquire().await?;
|
|
|
sqlx::query(
|
|
|
"INSERT OR REPLACE INTO coins
|
|
|
- (coin, serial, coin_blind, valcom_blind, value,
|
|
|
+ (coin, serial, coin_blind, valcom_blind, token_blind, value,
|
|
|
network, drk_address, net_address,
|
|
|
secret, is_spent, nullifier, leaf_position)
|
|
|
VALUES
|
|
|
- (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12);",
|
|
|
+ (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13);",
|
|
|
)
|
|
|
.bind(coin)
|
|
|
.bind(serial)
|
|
|
.bind(coin_blind)
|
|
|
.bind(value_blind)
|
|
|
- .bind(value.to_vec())
|
|
|
- .bind(serialize(network))
|
|
|
+ .bind(token_blind)
|
|
|
+ .bind(value)
|
|
|
+ .bind(network)
|
|
|
.bind(drk_address) // token_id
|
|
|
.bind(net_address)
|
|
|
.bind(secret)
|
|
|
@@ -348,7 +352,7 @@ impl WalletDb {
|
|
|
|
|
|
pub async fn confirm_spend_coin(&self, coin: &Coin) -> Result<()> {
|
|
|
debug!("Confirm spend coin");
|
|
|
- let is_spent: u32 = 1;
|
|
|
+ let is_spent = 1;
|
|
|
let coin = serialize(coin);
|
|
|
|
|
|
let mut conn = self.conn.acquire().await?;
|
|
|
@@ -376,9 +380,7 @@ impl WalletDb {
|
|
|
|
|
|
let mut list = vec![];
|
|
|
for row in rows {
|
|
|
- // TODO: FIXME:
|
|
|
- let value_bytes: Vec<u8> = row.get("value");
|
|
|
- let value = u64::from_le_bytes(value_bytes.try_into().unwrap());
|
|
|
+ let value = deserialize(row.get("value"))?;
|
|
|
let token_id = deserialize(row.get("drk_address"))?;
|
|
|
let nullifier = deserialize(row.get("nullifier"))?;
|
|
|
list.push(Balance { token_id, value, nullifier });
|
|
|
@@ -409,7 +411,7 @@ impl WalletDb {
|
|
|
pub async fn token_id_exists(&self, token_id: DrkTokenId) -> Result<bool> {
|
|
|
debug!("Checking if token ID exists");
|
|
|
|
|
|
- let is_spent: u32 = 0;
|
|
|
+ let is_spent = 0;
|
|
|
let id = serialize(&token_id);
|
|
|
|
|
|
let mut conn = self.conn.acquire().await?;
|
|
|
@@ -453,6 +455,7 @@ mod tests {
|
|
|
token_id: *t,
|
|
|
coin_blind: DrkCoinBlind::random(&mut OsRng),
|
|
|
value_blind: DrkValueBlind::random(&mut OsRng),
|
|
|
+ token_blind: DrkValueBlind::random(&mut OsRng),
|
|
|
};
|
|
|
|
|
|
let coin = Coin(pallas::Base::random(&mut OsRng));
|