|
@@ -31,7 +31,7 @@ pub trait ToBytes {
|
|
|
/// Bumped to 2 when `Cent` moved to a fixed 16-byte canonical encoding (ADR-0011).
|
|
/// Bumped to 2 when `Cent` moved to a fixed 16-byte canonical encoding (ADR-0011).
|
|
|
/// Bumped to 3 when `AccountId` gained a `subaccount` leg folded into its
|
|
/// Bumped to 3 when `AccountId` gained a `subaccount` leg folded into its
|
|
|
/// canonical bytes (ADR-0012).
|
|
/// canonical bytes (ADR-0012).
|
|
|
-pub const CANONICAL_VERSION: u8 = 3;
|
|
|
|
|
|
|
+pub const CANONICAL_VERSION: u8 = 4;
|
|
|
|
|
|
|
|
/// Append a `u16` in big-endian to `buf`.
|
|
/// Append a `u16` in big-endian to `buf`.
|
|
|
pub fn write_u16(buf: &mut Vec<u8>, v: u16) {
|
|
pub fn write_u16(buf: &mut Vec<u8>, v: u16) {
|
|
@@ -660,17 +660,6 @@ pub struct NewPosting {
|
|
|
// Transfer
|
|
// Transfer
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-/// Fixed-width secondary identifiers.
|
|
|
|
|
-#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
|
|
|
|
|
-pub struct UserData {
|
|
|
|
|
- /// 128-bit user-defined slot (e.g. external UUID).
|
|
|
|
|
- pub d128: u128,
|
|
|
|
|
- /// 64-bit user-defined slot (e.g. correlation id).
|
|
|
|
|
- pub d64: u64,
|
|
|
|
|
- /// 32-bit user-defined slot (e.g. category code).
|
|
|
|
|
- pub d32: u32,
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
/// Free-form key→value metadata.
|
|
/// Free-form key→value metadata.
|
|
|
pub type Metadata = BTreeMap<String, Vec<u8>>;
|
|
pub type Metadata = BTreeMap<String, Vec<u8>>;
|
|
|
|
|
|
|
@@ -687,8 +676,6 @@ pub struct Envelope {
|
|
|
pub account_snapshots: Vec<AccountSnapshotId>,
|
|
pub account_snapshots: Vec<AccountSnapshotId>,
|
|
|
/// Book this envelope belongs to.
|
|
/// Book this envelope belongs to.
|
|
|
pub book: BookId,
|
|
pub book: BookId,
|
|
|
- /// Fixed-width secondary identifiers.
|
|
|
|
|
- pub user_data: UserData,
|
|
|
|
|
/// Free-form key-value metadata.
|
|
/// Free-form key-value metadata.
|
|
|
pub metadata: Metadata,
|
|
pub metadata: Metadata,
|
|
|
}
|
|
}
|
|
@@ -714,11 +701,6 @@ impl Envelope {
|
|
|
self.book
|
|
self.book
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /// Fixed-width secondary identifiers.
|
|
|
|
|
- pub fn user_data(&self) -> &UserData {
|
|
|
|
|
- &self.user_data
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/// Free-form key-value metadata.
|
|
/// Free-form key-value metadata.
|
|
|
pub fn metadata(&self) -> &Metadata {
|
|
pub fn metadata(&self) -> &Metadata {
|
|
|
&self.metadata
|
|
&self.metadata
|
|
@@ -772,12 +754,6 @@ impl EnvelopeBuilder {
|
|
|
self
|
|
self
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /// Set the fixed-width secondary identifiers.
|
|
|
|
|
- pub fn user_data(mut self, user_data: UserData) -> Self {
|
|
|
|
|
- self.envelope.user_data = user_data;
|
|
|
|
|
- self
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/// Set the account version pins.
|
|
/// Set the account version pins.
|
|
|
pub fn account_snapshots(mut self, snapshots: Vec<AccountSnapshotId>) -> Self {
|
|
pub fn account_snapshots(mut self, snapshots: Vec<AccountSnapshotId>) -> Self {
|
|
|
self.envelope.account_snapshots = snapshots;
|
|
self.envelope.account_snapshots = snapshots;
|
|
@@ -865,16 +841,14 @@ pub struct Account {
|
|
|
pub flags: AccountFlags,
|
|
pub flags: AccountFlags,
|
|
|
/// Book this entity belongs to.
|
|
/// Book this entity belongs to.
|
|
|
pub book: BookId,
|
|
pub book: BookId,
|
|
|
- /// Fixed-width secondary identifiers.
|
|
|
|
|
- pub user_data: UserData,
|
|
|
|
|
/// Free-form key-value metadata.
|
|
/// Free-form key-value metadata.
|
|
|
pub metadata: Metadata,
|
|
pub metadata: Metadata,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
impl Account {
|
|
impl Account {
|
|
|
/// Create a version-1 main-subaccount account with the given policy: no flags,
|
|
/// Create a version-1 main-subaccount account with the given policy: no flags,
|
|
|
- /// the default book, and empty user data / metadata. Convenience for the common
|
|
|
|
|
- /// case — set the other fields explicitly when you need them.
|
|
|
|
|
|
|
+ /// the default book, and empty metadata. Convenience for the common case; set
|
|
|
|
|
+ /// the other fields explicitly when you need them.
|
|
|
pub fn new(id: AccountId, policy: AccountPolicy) -> Self {
|
|
pub fn new(id: AccountId, policy: AccountPolicy) -> Self {
|
|
|
Self::new_ref(id, policy)
|
|
Self::new_ref(id, policy)
|
|
|
}
|
|
}
|
|
@@ -887,7 +861,6 @@ impl Account {
|
|
|
policy,
|
|
policy,
|
|
|
flags: AccountFlags::empty(),
|
|
flags: AccountFlags::empty(),
|
|
|
book: DEFAULT_BOOK,
|
|
book: DEFAULT_BOOK,
|
|
|
- user_data: UserData::default(),
|
|
|
|
|
metadata: Metadata::new(),
|
|
metadata: Metadata::new(),
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -946,8 +919,6 @@ pub struct Transfer {
|
|
|
pub movements: Vec<Movement>,
|
|
pub movements: Vec<Movement>,
|
|
|
/// Book this entity belongs to.
|
|
/// Book this entity belongs to.
|
|
|
pub book: BookId,
|
|
pub book: BookId,
|
|
|
- /// Fixed-width secondary identifiers.
|
|
|
|
|
- pub user_data: UserData,
|
|
|
|
|
/// Free-form key-value metadata.
|
|
/// Free-form key-value metadata.
|
|
|
pub metadata: Metadata,
|
|
pub metadata: Metadata,
|
|
|
}
|
|
}
|
|
@@ -1030,12 +1001,6 @@ impl TransferBuilder {
|
|
|
self
|
|
self
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /// Set the fixed-width secondary identifiers.
|
|
|
|
|
- pub fn user_data(mut self, user_data: UserData) -> Self {
|
|
|
|
|
- self.transfer.user_data = user_data;
|
|
|
|
|
- self
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/// Set the free-form metadata.
|
|
/// Set the free-form metadata.
|
|
|
pub fn metadata(mut self, metadata: Metadata) -> Self {
|
|
pub fn metadata(mut self, metadata: Metadata) -> Self {
|
|
|
self.transfer.metadata = metadata;
|
|
self.transfer.metadata = metadata;
|
|
@@ -1093,16 +1058,6 @@ impl ToBytes for PostingId {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-impl ToBytes for UserData {
|
|
|
|
|
- fn to_bytes(&self) -> Vec<u8> {
|
|
|
|
|
- let mut buf = Vec::with_capacity(28);
|
|
|
|
|
- write_u128(&mut buf, self.d128);
|
|
|
|
|
- write_u64(&mut buf, self.d64);
|
|
|
|
|
- write_u32(&mut buf, self.d32);
|
|
|
|
|
- buf
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
impl ToBytes for AccountPolicy {
|
|
impl ToBytes for AccountPolicy {
|
|
|
fn to_bytes(&self) -> Vec<u8> {
|
|
fn to_bytes(&self) -> Vec<u8> {
|
|
|
let mut buf = Vec::with_capacity(9);
|
|
let mut buf = Vec::with_capacity(9);
|
|
@@ -1186,7 +1141,6 @@ impl ToBytes for Envelope {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
buf.extend(self.book.to_bytes());
|
|
buf.extend(self.book.to_bytes());
|
|
|
- buf.extend(self.user_data.to_bytes());
|
|
|
|
|
|
|
|
|
|
write_u32(&mut buf, self.metadata.len() as u32);
|
|
write_u32(&mut buf, self.metadata.len() as u32);
|
|
|
for (key, value) in &self.metadata {
|
|
for (key, value) in &self.metadata {
|
|
@@ -1210,7 +1164,6 @@ impl ToBytes for Account {
|
|
|
buf.extend(self.policy.to_bytes());
|
|
buf.extend(self.policy.to_bytes());
|
|
|
buf.extend(self.flags.to_bytes());
|
|
buf.extend(self.flags.to_bytes());
|
|
|
buf.extend(self.book.to_bytes());
|
|
buf.extend(self.book.to_bytes());
|
|
|
- buf.extend(self.user_data.to_bytes());
|
|
|
|
|
|
|
|
|
|
write_u32(&mut buf, self.metadata.len() as u32);
|
|
write_u32(&mut buf, self.metadata.len() as u32);
|
|
|
for (key, value) in &self.metadata {
|
|
for (key, value) in &self.metadata {
|