bk_set_update.rs

Overview

This file provides the API structures, serialization/deserialization logic, data handling, and HTTP request handling related to the management and updating of a "Backup Key Set" (BkSet) within the system. The BkSet represents collections of backup keys involved in some form of blockchain or distributed system consensus or staking mechanism.

Key functionalities include:

Data Structures and Classes

ApiUInt256

Example usage:

let raw_bytes = [0u8; 32];
let api_uint = ApiUInt256(raw_bytes);
let json_string = serde_json::to_string(&api_uint).unwrap();
// json_string is a hex string representing the 32 bytes.

ApiPubKey

ApiBk

ApiBkStatus

ApiBkSet

ApiBkSetSnapshot

ApiBkSetResponse

ApiBkSetError

ApiBkSetHandler

render_error_response

Important Implementation Details

Interaction with Other System Components

Visual Diagram: Class and Structure Relationships

classDiagram
class ApiUInt256 {
+[u8; 32]
+serialize()
+deserialize()
}
class ApiPubKey {
+[u8; 48]
+serialize()
+deserialize()
}
class ApiBkStatus {
<<enum>>
+PreEpoch
+Active
+CalledToFinish
+Expired
}
class ApiBk {
+ApiPubKey pubkey
+Option<u64> epoch_finish_seq_no
+u64 wait_step
+ApiBkStatus status
+String address
+String stake
+ApiUInt256 owner_address
+usize signer_index
+ApiUInt256 owner_pubkey
+Option<u64> ttl_seq_no
+expired()
}
class ApiBkSet {
+u64 seq_no
+Vec<ApiBk> current
+Vec<ApiBk> future
+update()
-update_bks()
}
class ApiBkSetSnapshot {
-SystemTime update_time
-ApiBkSet bk_set
+new()
+replace()
}
class ApiBkSetResponse {
+Option<ApiBkSet> result
+Option<ApiBkSetError> error
}
class ApiBkSetError {
+String code
+String message
}
class ApiBkSetHandler {
+new()
+handle()
}
ApiBkSet "1" --> "*" ApiBk : contains
ApiBkSetSnapshot "1" --> "1" ApiBkSet : holds
ApiBkSetResponse "1" --> "0..1" ApiBkSet : result
ApiBkSetResponse "1" --> "0..1" ApiBkSetError : error
ApiBkSetHandler ..> ApiBkSetSnapshot : reads
ApiBk ..|> ApiBkStatus : uses
ApiBk ..> ApiUInt256 : uses
ApiBk ..> ApiPubKey : uses

This diagram illustrates the main data structures' relationships, showing how ApiBkSet aggregates multiple ApiBk entries, the snapshot mechanism around ApiBkSet, and the handler's role in accessing and serving this data. Serialization-related types (ApiUInt256 and ApiPubKey) are used within ApiBk. The handler interacts with the snapshot to provide HTTP responses.