Skip to content

Commit cc864c6

Browse files
authored
Small api fixes (#8)
1. Add alias for `enc_keys` field. 2. Add SQLx support for `AccountPublicKeys`.
1 parent e341dba commit cc864c6

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

.github/workflows/dart-bp-tests.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ on:
99
- 'Cargo.toml' # Root workspace file
1010
pull_request:
1111
branches: [ main ]
12-
paths:
13-
- 'dart-bp/**'
14-
- 'dart-common/**'
15-
- 'Cargo.toml'
1612

1713
env:
1814
CARGO_TERM_COLOR: always

src/bp/asset.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl From<&AssetState> for AssetKeysLookup {
7373
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7474
pub struct AssetKeys {
7575
/// The encryption keys for auditors and mediators are stored in a set to ensure uniqueness.
76+
#[cfg_attr(feature = "serde", serde(alias = "encKeys"))]
7677
pub enc_keys: BTreeSet<EncryptionPublicKey>,
7778
/// The mediators are stored as a map from their `affirmation_key` to their encryption key.
7879
pub mediators: BTreeMap<AccountPublicKey, u8>,

src/bp/sqlx_impl.rs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
22
use sqlx::{Database, Decode, Encode, Type, encode::IsNull};
33

44
use super::{
5-
AccountPublicKey, AccountSecretKey, AccountStateCommitment, AccountStateNullifier,
6-
EncryptionPublicKey, EncryptionSecretKey, FeeAccountStateCommitment, FeeAccountStateNullifier,
7-
LegEncrypted, SettlementRef,
5+
AccountPublicKey, AccountPublicKeys, AccountSecretKey, AccountStateCommitment,
6+
AccountStateNullifier, EncryptionPublicKey, EncryptionSecretKey, FeeAccountStateCommitment,
7+
FeeAccountStateNullifier, LegEncrypted, SettlementRef,
88
};
99

1010
// SettlementRef is stored as a BLOB in the database
@@ -124,6 +124,45 @@ where
124124
}
125125
}
126126

127+
// AccountPublicKeys is stored as a BLOB in the database
128+
129+
impl<DB: Database> Type<DB> for AccountPublicKeys
130+
where
131+
// Make sure BLOBs are supported by the database
132+
Vec<u8>: Type<DB>,
133+
{
134+
fn type_info() -> DB::TypeInfo {
135+
<Vec<u8> as Type<DB>>::type_info()
136+
}
137+
}
138+
139+
impl<'r, DB: Database> Decode<'r, DB> for AccountPublicKeys
140+
where
141+
// Make sure BLOBs are supported by the database
142+
Vec<u8>: Decode<'r, DB>,
143+
{
144+
fn decode(
145+
value: DB::ValueRef<'r>,
146+
) -> Result<AccountPublicKeys, Box<dyn core::error::Error + 'static + Send + Sync>> {
147+
let value = <Vec<u8> as Decode<DB>>::decode(value)?;
148+
Ok(codec::Decode::decode(&mut &value[..])?)
149+
}
150+
}
151+
152+
impl<'r, DB: Database> Encode<'r, DB> for AccountPublicKeys
153+
where
154+
// Make sure BLOBs are supported by the database
155+
Vec<u8>: Encode<'r, DB>,
156+
{
157+
fn encode_by_ref(
158+
&self,
159+
buf: &mut DB::ArgumentBuffer<'r>,
160+
) -> Result<IsNull, Box<dyn core::error::Error + 'static + Send + Sync>> {
161+
let value = codec::Encode::encode(self);
162+
Encode::<'r, DB>::encode(value, buf)
163+
}
164+
}
165+
127166
// AccountSecretKey is stored as a BLOB in the database
128167

129168
impl<DB: Database> Type<DB> for AccountSecretKey

0 commit comments

Comments
 (0)