계약의 신뢰성 향상
견고한 업그레이드 — 데이터 및 어플리케이션 계약
스마트 계약은 일단 배치되면 변경할 수 없다.그러나 배포 후 계약을 변경할 수 있는 충분한 이유가 있습니다.
단순 계약: Num
Num.sol:
// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.8.0 < 0.9.0;
contract Num {
uint num;
function set(uint n) external {
num = n;
}
function get() external view returns (uint) {
return num;
}
}
우리는 실제 응용 프로그램이 아니라 분리하는 방법에 주목할 것이다// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.8.0 < 0.9.0;
contract NumApp {
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.8.0 < 0.9.0;
contract NumApp {
function set(uint n) external {
num = n;
}
function get() external view returns (uint) {
return num;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.8.0 < 0.9.0;
contract NumApp {
function setNum(uint n) external {
set(n);
}
function getNum() ex returns (uint) {
return get();
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.8.0 < 0.9.0;
contract NumApp {
function setNum(uint n) external {
set(n);
}
function getNum() external returns (uint) {
return get();
}
}
interface Num {
set(uint n) external;
get() external returns (uint);
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.8.0 < 0.9.0;
contract NumApp {
Num dataContract;
constructor(address dataContractAddress) {
dataContract = Num(dataContractAddress);
}
function setNum(uint n) external {
set(n);
}
function getNum() external returns (uint) {
return get();
}
}
interface Num {
set(uint n) external;
get() external returns (uint);
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.8.0 < 0.9.0;
contract NumApp {
Num dataContract;
constructor(address dataContractAddress) {
dataContract = Num(dataContractAddress);
}
function setNum(uint n) external {
dataContract.set(n);
}
function getNum() external returns (uint) {
return dataContract.get();
}
}
interface Num {
set(uint n) external;
get() external returns (uint);
}
address private contractOwner
constructor() {
contractOwner = msg.sender;
}
modifier requireContractOwner() {
require(msg.sender == contractOwner, "Caller is not contract owner");
_;
}
function authorizeContract(address appContract) external requireContractOwner {
authorizedContracts[appContract] = true;
}
function deauthorizeContract(address appContract) external requireContractOwner {
delete authorizedContracts[appContract];
}
modifier isCallerAuthorized() {
require(authorizedContracts[msg.sender] == true, "Caller is not authorized");
_;
}
최종 데이터 계약
// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.8.0 < 0.9.0;
contract Num {
uint num;
address private contractOwner;
mapping(address => bool) private authorizedContracts;
constructor() {
contractOwner = msg.sender;
}
modifier requireContractOwner() {
require(msg.sender == contractOwner, "Caller is not contract owner");
_;
}
modifier isCallerAuthorized() {
require(authorizedContracts[msg.sender] == true, "Caller is not authorized");
_;
}
function authorizeContract(address appContract) external requireContractOwner {
authorizedContracts[appContract] = true;
}
function deauthorizeContract(address appContract) external requireContractOwner {
delete authorizedContracts[appContract];
}
function set(uint n) external isCallerAuthorized {
num = n;
}
function get() external view isCallerAuthorized returns (uint) {
return num;
}
}
최종 애플리케이션 계약
// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.8.0 < 0.9.0;
contract NumApp {
Num dataContract;
constructor(address dataContractAddress) {
dataContract = Num(dataContractAddress);
}
function setNum(uint n) external {
dataContract.set(n);
}
function getNum() external view returns (uint) {
return dataContract.get();
}
}
interface Num {
function set(uint n) external;
function get() external view returns (uint);
}
배포 및 테스트 방법
주의해야 할 점:
의견과 건의를 환영합니다.
Join Coinmonks Telegram group and learn about crypto trading and investing
읽다
무엇이 a입니까?
Grid Trading | 3Commas Review | Pionex Review
Coinrule review | AAX Exchange Review | Deribit Review
NGRAVE ZERO review | Bybit Exchange Review | Bityard Review
Ledger vs Ngrave | Crypto Copy Trading Platforms
ledger nano s vs x | Vauld Review | YouHodler Review
Ledger Nano S vs Trezor one vs Trezor T vs Ledger Nano X | BlockFi vs Celsius
Hodlnaut Review | Bitsgap review
Quadency Review | Ellipal Titan Review
SecuX Stone Review | 암호화 소프트웨어
BlockFi Review 및 DEX Explorer
Blockchain APIs지침: 초보자는 어떻게 돈을 버는가
best books to learn about Bitcoin
Reference
이 문제에 관하여(계약의 신뢰성 향상), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/coinmonks/upgrade-contracts-in-solidity-42o5텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)