Skip to content

Commit

Permalink
[Contract] Change memory to calldata in parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Oct 5, 2023
1 parent 3b210bd commit fd789ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/contracts/contracts/CurrencyRate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ contract CurrencyRate {
/// @notice 통화에 대한 가격을 저장한다.
/// @param _currency 통화명
/// @param _price 토큰의 가격
function set(string memory _currency, uint256 _price) public onlyValidator(msg.sender) {
function set(string calldata _currency, uint256 _price) public onlyValidator(msg.sender) {
prices[_currency] = _price;

emit SetPrice(_currency, _price);
}

/// @notice 통화에 대한 가격을 제공한다.
/// @param _currency 통화명
function get(string memory _currency) public view returns (uint256) {
function get(string calldata _currency) public view returns (uint256) {
return prices[_currency];
}
}
14 changes: 7 additions & 7 deletions packages/contracts/contracts/Ledger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ contract Ledger {
function providePoint(
address _account,
uint256 _amount,
string memory _purchaseId,
string memory _shopId
string calldata _purchaseId,
string calldata _shopId
) internal {
pointBalances[_account] += _amount;
emit ProvidedPoint(_account, _amount, _amount, pointBalances[_account], _purchaseId, _shopId);
Expand All @@ -266,8 +266,8 @@ contract Ledger {
function provideUnPayablePoint(
bytes32 _phone,
uint256 _amount,
string memory _purchaseId,
string memory _shopId
string calldata _purchaseId,
string calldata _shopId
) internal {
unPayablePointBalances[_phone] += _amount;
emit ProvidedUnPayablePoint(_phone, _amount, _amount, unPayablePointBalances[_phone], _purchaseId, _shopId);
Expand All @@ -282,8 +282,8 @@ contract Ledger {
function provideToken(
address _account,
uint256 _amount,
string memory _purchaseId,
string memory _shopId
string calldata _purchaseId,
string calldata _shopId
) internal {
uint256 amountToken = convertPointToToken(_amount);

Expand Down Expand Up @@ -504,7 +504,7 @@ contract Ledger {

/// @notice 구매 데이터를 리턴한다
/// @param _purchaseId 구매 아이디
function purchaseOf(string memory _purchaseId) public view returns (PurchaseData memory) {
function purchaseOf(string calldata _purchaseId) public view returns (PurchaseData memory) {
return purchases[_purchaseId];
}

Expand Down
16 changes: 8 additions & 8 deletions packages/contracts/contracts/ShopCollection.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ contract ShopCollection {
/// @param _provideWaitTime 제품구매 후 포인트가 지급될 시간
/// @param _providePercent 구매금액에 대한 포인트 지급량
function add(
string memory _shopId,
string calldata _shopId,
uint256 _provideWaitTime,
uint256 _providePercent,
bytes32 _phone
) public onlyValidator(msg.sender) {
_add(_shopId, _provideWaitTime, _providePercent, _phone);
}

function _add(string memory _shopId, uint256 _provideWaitTime, uint256 _providePercent, bytes32 _phone) internal {
function _add(string calldata _shopId, uint256 _provideWaitTime, uint256 _providePercent, bytes32 _phone) internal {
require(_phone != NULL, "Invalid phone");

if (shops[_shopId].status == ShopStatus.INVALID) {
Expand Down Expand Up @@ -150,31 +150,31 @@ contract ShopCollection {
}

/// @notice 지급된 총 마일지리를 누적한다
function addProvidedPoint(string memory _shopId, uint256 _amount, string memory _purchaseId) public onlyLedger {
function addProvidedPoint(string calldata _shopId, uint256 _amount, string calldata _purchaseId) public onlyLedger {
if (shops[_shopId].status != ShopStatus.INVALID) {
shops[_shopId].providedPoint += _amount;
emit IncreasedProvidedPoint(_shopId, _amount, shops[_shopId].providedPoint, _purchaseId);
}
}

/// @notice 사용된 총 마일지리를 누적한다
function addUsedPoint(string memory _shopId, uint256 _amount, string memory _purchaseId) public onlyLedger {
function addUsedPoint(string calldata _shopId, uint256 _amount, string calldata _purchaseId) public onlyLedger {
if (shops[_shopId].status != ShopStatus.INVALID) {
shops[_shopId].usedPoint += _amount;
emit IncreasedUsedPoint(_shopId, _amount, shops[_shopId].usedPoint, _purchaseId);
}
}

/// @notice 정산된 총 마일지리를 누적한다
function addSettledPoint(string memory _shopId, uint256 _amount, string memory _purchaseId) public onlyLedger {
function addSettledPoint(string calldata _shopId, uint256 _amount, string calldata _purchaseId) public onlyLedger {
if (shops[_shopId].status != ShopStatus.INVALID) {
shops[_shopId].settledPoint += _amount;
emit IncreasedSettledPoint(_shopId, _amount, shops[_shopId].settledPoint, _purchaseId);
}
}

/// @notice 정산되어야 할 마일지리의 량을 리턴합니다.
function getSettlementPoint(string memory _shopId) public view returns (uint256) {
function getSettlementPoint(string calldata _shopId) public view returns (uint256) {
if (shops[_shopId].status == ShopStatus.ACTIVE) {
ShopData memory data = shops[_shopId];
if (data.providedPoint + data.settledPoint < data.usedPoint) {
Expand All @@ -189,7 +189,7 @@ contract ShopCollection {

/// @notice 상점 데이터를 리턴한다
/// @param _shopId 상점의 아이디
function shopOf(string memory _shopId) public view returns (ShopData memory) {
function shopOf(string calldata _shopId) public view returns (ShopData memory) {
return shops[_shopId];
}

Expand All @@ -212,7 +212,7 @@ contract ShopCollection {

/// @notice 인출가능한 정산금액을 리턴한다.
/// @param _shopId 상점의 아이디
function withdrawableOf(string memory _shopId) public view returns (uint256) {
function withdrawableOf(string calldata _shopId) public view returns (uint256) {
ShopData memory shop = shops[_shopId];
return shop.settledPoint - shop.withdrawnPoint;
}
Expand Down

0 comments on commit fd789ed

Please sign in to comment.