Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

feat: add model upgradeability check (n-03) #33

Merged
merged 5 commits into from
Nov 11, 2024
Merged

feat: add model upgradeability check (n-03) #33

merged 5 commits into from
Nov 11, 2024

Conversation

glihm
Copy link
Contributor

@glihm glihm commented Nov 5, 2024

No description provided.

@glihm glihm changed the base branch from main to bp-1 November 5, 2024 21:54
Comment on lines +605 to +608
self
.assert_resource_upgradability(
@namespace, @model_name, prev_address, new_contract_address
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most notable change, for model and event.

Comment on lines +1066 to +1087
fn assert_resource_upgradability(
self: @ContractState,
namespace: @ByteArray,
name: @ByteArray,
prev_address: ContractAddress,
new_address: ContractAddress
) {
let resource = IStoredResourceDispatcher { contract_address: prev_address };
let old_layout = resource.layout();
let old_schema = resource.schema();

let new_resource = IStoredResourceDispatcher { contract_address: new_address };
let new_layout = new_resource.layout();
let new_schema = new_resource.schema();

if !new_layout.is_same_type_of(@old_layout) {
panic_with_byte_array(@errors::invalid_resource_layout_upgrade(namespace, name));
}

if !new_schema.is_an_upgrade_of(@old_schema) {
panic_with_byte_array(@errors::invalid_resource_schema_upgrade(namespace, name));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New function without side effect only to check if a model/event is a good candidate for upgradeability.

@glihm glihm changed the title Add model upgradeability check feat: add model upgradeability check (n-03) Nov 5, 2024
@glihm glihm merged commit 20080a1 into bp-1 Nov 11, 2024
4 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant