Skip to content

Commit

Permalink
Merge pull request #37 from tonlabs/0.26.1-rc
Browse files Browse the repository at this point in the history
Version 0.26.1
  • Loading branch information
g9d authored Sep 16, 2020
2 parents 9562392 + 850f9fe commit 68cb845
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Release Notes
All notable changes to this project will be documented in this file.

## 0.26.1 - Sep 16, 2020

### Fixed
- test contracts BankCollector & ContractDeployer to pass with new compiler
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ton-client-node-js",
"version": "0.26.0",
"version": "0.26.1",
"description": "TON Client Library for Node.Js",
"main": "index.js",
"scripts": {
Expand Down
46 changes: 25 additions & 21 deletions sample/__tests__/contracts/BankCollector.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity >=0.5.0;

// Interface to the bank client.
abstract contract IBankClient {
function demandDebt(uint amount) public virtual;
Expand All @@ -7,8 +8,8 @@ abstract contract IBankClient {

// Interface to the bank collector.
abstract contract IBankCollector {
function receivePayment() public payable virtual;
function getDebtAmount() public payable virtual;
function receivePayment() public virtual;
function getDebtAmount() public virtual;
}


Expand All @@ -17,7 +18,7 @@ contract BankCollector is IBankCollector {

// Modifier that allows public function to accept all external calls.
modifier onlyOwner {
// Runtime functions to obtain message sender pubkey and contract pubkey.
// Runtime functions to obtain message sender pubkey and contract pubkey.
require(msg.pubkey() == tvm.pubkey());

// Runtime function that allows contract to process inbound messages spending
Expand All @@ -43,37 +44,39 @@ contract BankCollector is IBankCollector {
// Add client to database.
function addClient(address addr, uint debtAmount) public onlyOwner {
// Mapping member function to obtain value from mapping if it exists.
(bool exists, ClientInfo info) = clientDB.fetch(addr);
if (exists) {
info.debtAmount += debtAmount;
clientDB[addr] = info;
optional(ClientInfo) info = clientDB.fetch(addr);
if (info.hasValue()) {
ClientInfo i = info.get();
i.debtAmount += debtAmount;
clientDB[addr] = i;
} else {
clientDB[addr] = ClientInfo(debtAmount, uint32(now) + EXPIRATION_PERIOD);
}
}

// Function for client to get his debt amount.
function getDebtAmount() public payable override {
function getDebtAmount() public override {
// Mapping member function to obtain value from mapping if it exists.
(bool exists, ClientInfo info) = clientDB.fetch(msg.sender);
if (exists) {
IBankClient(msg.sender).setDebtAmount(info.debtAmount);
optional(ClientInfo) info = clientDB.fetch(msg.sender);
if (info.hasValue()) {
IBankClient(msg.sender).setDebtAmount(info.get().debtAmount);
} else {
IBankClient(msg.sender).setDebtAmount(0);
}
}

// Function for client to return debt.
function receivePayment() public payable override {
function receivePayment() public override {
address addr = msg.sender;
// Mapping member function to obtain value from mapping if it exists.
(bool exists, ClientInfo info) = clientDB.fetch(addr);
if (exists) {
if (info.debtAmount <= msg.value) {
optional(ClientInfo) info = clientDB.fetch(addr);
if (info.hasValue()) {
ClientInfo i = info.get();
if (i.debtAmount <= msg.value) {
delete clientDB[addr];
} else {
info.debtAmount -= msg.value;
clientDB[addr] = info;
i.debtAmount -= msg.value;
clientDB[addr] = i;
}
}
}
Expand All @@ -82,13 +85,14 @@ contract BankCollector is IBankCollector {
function demandExpiredDebts() public view onlyOwner {
uint32 curTime = uint32(now);
// Mapping member function to obtain minimal key and associated value from mapping if it exists.
(address addr, ClientInfo info, bool exists) = clientDB.min();
while(exists) {
optional(address, ClientInfo) client = clientDB.min();
while(client.hasValue()) {
(address addr, ClientInfo info) = client.get();
if (info.expiredTimestamp <= curTime)
IBankClient(addr).demandDebt(info.debtAmount);
// Mapping member function to obtain next key and associated value from mapping if it exists.
(addr, info, exists) = clientDB.next(addr);
client = clientDB.next(addr);
}
}

}
}
6 changes: 3 additions & 3 deletions sample/__tests__/contracts/ContractDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ contract ContractDeployer {

// Function that allows to get information about contract with given ID.
function getContractInfo(uint ID) public view acceptOnlyOwner returns (bool, address, TvmCell, uint256) {
(bool exists, DeployedContract contr) = contracts.fetch(ID);
if (exists)
return (true, contr.addr, contr.stateInit, contr.pubkey);
optional(DeployedContract) contr = contracts.fetch(ID);
if (contr.hasValue())
return (true, contr.get().addr, contr.get().stateInit, contr.get().pubkey);
TvmCell cell;
return (false, address(0), cell, 0);
}
Expand Down
Binary file modified sample/__tests__/contracts/ContractDeployer.tvc
Binary file not shown.

0 comments on commit 68cb845

Please sign in to comment.