feat(sncast): Add versioned accounts schema - #4548
Conversation
df091b9 to
3febf64
Compare
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||
| pub struct Account { | ||
| pub public_key: Felt, | ||
| pub address: Option<Felt>, |
There was a problem hiding this comment.
Why address is Option? 🤔
There was a problem hiding this comment.
It leaked from the previous logic, where native cast accounts were mixed with starkli ones. I changed the domain model and both schemas to enforce the address
| impl VersionedAccountsFile { | ||
| pub fn decode(input: &[u8]) -> Result<Self, AccountsError> { | ||
| if input.iter().all(u8::is_ascii_whitespace) { | ||
| return Ok(Self::V1(v1::AccountsFile::default())); |
There was a problem hiding this comment.
Why V1 for an empty file?
There was a problem hiding this comment.
It's a natural solution - V1 file can technically be empty, while the V2 contains at least a version
There was a problem hiding this comment.
What if someone creates an empty file and wants to add an account there?
There was a problem hiding this comment.
It will be deserialized as V1. Any modifications (writes/removes) will happen via AccountRepository.mutate that converts the content to the latest schema version
8b5ac73 to
3ecaf12
Compare
f62a6eb to
adff940
Compare
d69ff65 to
d5d3943
Compare
d5d3943 to
3da4f05
Compare
3da4f05 to
be70592
Compare
| impl VersionedAccountsFile { | ||
| pub fn decode(input: &[u8]) -> Result<Self, AccountsError> { | ||
| if input.iter().all(u8::is_ascii_whitespace) { | ||
| return Ok(Self::V1(v1::AccountsFile::default())); |
There was a problem hiding this comment.
What if someone creates an empty file and wants to add an account there?
be70592 to
3f8188a
Compare
3f8188a to
b194201
Compare
cbc82f8 to
db06d71
Compare
0a63276 to
6e21e2d
Compare
270b677 to
c4ee71c
Compare
c4ee71c to
baa5911
Compare
baa5911 to
bea8623
Compare
Introduced changes
This PR introduces a versioned schema of the accounts file:
private_keyandledger_pathfields becomes the legacyv1variant. Its behaviour remains exactly the same.signerfield, deserialized as a tagged enum, is the latestv2variant.Both variants converge to the common
AccountsRegistrystructure that holds the accounts' data expressed using domain models from #4547.Utility functions in
sncast::accounts::schema::migrationsallow upgradingv1tov2.Checklist
CHANGELOG.md