-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the
/object/attached-modules/royalty
endpoint.
- Loading branch information
1 parent
6d4f9de
commit 55d576f
Showing
17 changed files
with
998 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
core-rust/node-http-apis/src/engine_state_api/generated/models/object_method_royalty.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Engine State API | ||
* | ||
* This API provides a complete view of the current ledger state, operating at a relatively low level (i.e. returning Entities' data and type information in a generic way, without interpreting specifics of different native or custom components). It mirrors how the Radix Engine views the ledger state in its \"System\" layer, and thus can be useful for Scrypto developers, who need to inspect how the Engine models and stores their application's state, or how an interface / authentication scheme of another component looks like. | ||
* | ||
* The version of the OpenAPI document: v0.0.1 | ||
* | ||
* Generated by: https://openapi-generator.tech | ||
*/ | ||
|
||
|
||
|
||
|
||
#[derive(Clone, Debug, PartialEq, Default, serde::Serialize, serde::Deserialize)] | ||
pub struct ObjectMethodRoyalty { | ||
/// Method name. | ||
#[serde(rename = "name")] | ||
pub name: String, | ||
#[serde(rename = "component_royalty_amount", skip_serializing_if = "Option::is_none")] | ||
pub component_royalty_amount: Option<Box<crate::engine_state_api::generated::models::RoyaltyAmount>>, | ||
#[serde(rename = "package_royalty_amount", skip_serializing_if = "Option::is_none")] | ||
pub package_royalty_amount: Option<Box<crate::engine_state_api::generated::models::RoyaltyAmount>>, | ||
} | ||
|
||
impl ObjectMethodRoyalty { | ||
pub fn new(name: String) -> ObjectMethodRoyalty { | ||
ObjectMethodRoyalty { | ||
name, | ||
component_royalty_amount: None, | ||
package_royalty_amount: None, | ||
} | ||
} | ||
} | ||
|
||
|
29 changes: 29 additions & 0 deletions
29
core-rust/node-http-apis/src/engine_state_api/generated/models/object_royalty_request.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Engine State API | ||
* | ||
* This API provides a complete view of the current ledger state, operating at a relatively low level (i.e. returning Entities' data and type information in a generic way, without interpreting specifics of different native or custom components). It mirrors how the Radix Engine views the ledger state in its \"System\" layer, and thus can be useful for Scrypto developers, who need to inspect how the Engine models and stores their application's state, or how an interface / authentication scheme of another component looks like. | ||
* | ||
* The version of the OpenAPI document: v0.0.1 | ||
* | ||
* Generated by: https://openapi-generator.tech | ||
*/ | ||
|
||
|
||
|
||
|
||
#[derive(Clone, Debug, PartialEq, Default, serde::Serialize, serde::Deserialize)] | ||
pub struct ObjectRoyaltyRequest { | ||
/// A Bech32m-encoded, human readable rendering of an arbitrary Entity's address. | ||
#[serde(rename = "entity_address")] | ||
pub entity_address: String, | ||
} | ||
|
||
impl ObjectRoyaltyRequest { | ||
pub fn new(entity_address: String) -> ObjectRoyaltyRequest { | ||
ObjectRoyaltyRequest { | ||
entity_address, | ||
} | ||
} | ||
} | ||
|
||
|
31 changes: 31 additions & 0 deletions
31
core-rust/node-http-apis/src/engine_state_api/generated/models/object_royalty_response.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Engine State API | ||
* | ||
* This API provides a complete view of the current ledger state, operating at a relatively low level (i.e. returning Entities' data and type information in a generic way, without interpreting specifics of different native or custom components). It mirrors how the Radix Engine views the ledger state in its \"System\" layer, and thus can be useful for Scrypto developers, who need to inspect how the Engine models and stores their application's state, or how an interface / authentication scheme of another component looks like. | ||
* | ||
* The version of the OpenAPI document: v0.0.1 | ||
* | ||
* Generated by: https://openapi-generator.tech | ||
*/ | ||
|
||
|
||
|
||
|
||
#[derive(Clone, Debug, PartialEq, Default, serde::Serialize, serde::Deserialize)] | ||
pub struct ObjectRoyaltyResponse { | ||
#[serde(rename = "at_ledger_state")] | ||
pub at_ledger_state: Box<crate::engine_state_api::generated::models::LedgerStateSummary>, | ||
#[serde(rename = "method_royalties")] | ||
pub method_royalties: Vec<crate::engine_state_api::generated::models::ObjectMethodRoyalty>, | ||
} | ||
|
||
impl ObjectRoyaltyResponse { | ||
pub fn new(at_ledger_state: crate::engine_state_api::generated::models::LedgerStateSummary, method_royalties: Vec<crate::engine_state_api::generated::models::ObjectMethodRoyalty>) -> ObjectRoyaltyResponse { | ||
ObjectRoyaltyResponse { | ||
at_ledger_state: Box::new(at_ledger_state), | ||
method_royalties, | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
core-rust/node-http-apis/src/engine_state_api/handlers/object_royalty.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::engine_state_api::*; | ||
|
||
use crate::engine_prelude::*; | ||
|
||
use std::ops::Deref; | ||
|
||
pub(crate) async fn handle_object_royalty( | ||
state: State<EngineStateApiState>, | ||
Json(request): Json<models::ObjectRoyaltyRequest>, | ||
) -> Result<Json<models::ObjectRoyaltyResponse>, ResponseError> { | ||
let mapping_context = MappingContext::new(&state.network); | ||
let extraction_context = ExtractionContext::new(&state.network); | ||
|
||
let node_id = extract_address_as_node_id(&extraction_context, &request.entity_address) | ||
.map_err(|err| err.into_response_error("entity_address"))?; | ||
|
||
let database = state.state_manager.database.read_current(); | ||
let loader = ObjectRoyaltyLoader::new(database.deref()); | ||
|
||
let method_amounts = loader.load_method_amounts(&node_id)?; | ||
|
||
let header = read_current_ledger_header(database.deref()); | ||
|
||
Ok(Json(models::ObjectRoyaltyResponse { | ||
at_ledger_state: Box::new(to_api_ledger_state_summary(&mapping_context, &header)?), | ||
method_royalties: method_amounts | ||
.into_iter() | ||
.map(|method_amount| to_api_method_royalty(&mapping_context, method_amount)) | ||
.collect::<Result<Vec<_>, _>>()?, | ||
})) | ||
} | ||
|
||
fn to_api_method_royalty( | ||
_context: &MappingContext, | ||
method_amount: MethodRoyaltyAmount, | ||
) -> Result<models::ObjectMethodRoyalty, MappingError> { | ||
let MethodRoyaltyAmount { | ||
name, | ||
for_component, | ||
for_package, | ||
} = method_amount; | ||
Ok(models::ObjectMethodRoyalty { | ||
name, | ||
component_royalty_amount: to_api_royalty_amount(&for_component).map(Box::new), | ||
package_royalty_amount: to_api_royalty_amount(&for_package).map(Box::new), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.