본문으로 건너뛰기

자체 업그레이드 및 상태 마이그레이션

Three examples on how to handle updates and state migration:

  1. State Migration: How to implement a migrate method to migrate state between contract updates.
  2. State Versioning: How to use readily use versioning on a state, to simplify updating it later.
  3. Self Update: How to implement a contract that can update itself.

상태 마이그레이션

The State Migration example shows how to handle state-breaking changes between contract updates.

이는 두 가지 컨트랙트로 구성됩니다.

  1. Base: A Guest Book where people can write messages.
  2. 업데이트: 매개변수를 제거하고 내부 구조를 변경하는 업데이트입니다.
basic-updates/update/src/migrate.rs
loading...

마이그레이션 메서드

마이그레이션 메서드는 현재 상태(OldState)를 역직렬화하고 메시지를 반복하여, payment 필드를 포함하는 새 PostedMessage 메시지로 업데이트합니다.

Notice that migrate is actually an initialization method that ignores the existing state ([#init(ignore_state)]), thus being able to execute and rewrite the state.


상태 버전 관리

The State Versioning example shows how to use Enums to implement state versioning on a contract.

버전 관리는 새 버전의 구조를 추가하기만 하면 되므로 컨트랙트 업데이트를 간소화합니다. 모든 버전이 공존할 수 있으므로, 기존 구조를 변경할 필요가 없습니다.

이는 두 컨트랙트로 구성됩니다.

  1. 기본: 버전 관리된 PostedMessages(PostedMessagesV1)를 사용하는 방명록 컨트랙트
  2. 업데이트: 새로운 버전의 PostedMessages(PostedMessagesV2)를 추가하는 업데이트
enum-updates/update/src/versioned_msg.rs
loading...

Self Update

The Self Update example shows how to implement a contract that can update itself.

It is composed by 2 contracts:

  1. Base: A Guest Book were people can write messages, implementing a update_contract method.
    1. 업데이트: 매개변수를 제거하고 내부 구조를 변경하는 업데이트입니다.
self-updates/base/src/update.rs
loading...
Was this page helpful?