-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from tonlabs/1.5.1-rc
Version 1.5.1
- Loading branch information
Showing
22 changed files
with
472 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,40 @@ | ||
{ | ||
"ABI version": 2, | ||
"header": [ | ||
"time", | ||
"expire" | ||
], | ||
"functions": [ | ||
{ | ||
"name": "sendTransaction", | ||
"inputs": [ | ||
{ | ||
"name": "dest", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "value", | ||
"type": "uint128" | ||
}, | ||
{ | ||
"name": "bounce", | ||
"type": "bool" | ||
} | ||
], | ||
"outputs": [] | ||
}, | ||
{ | ||
"name": "getMessages", | ||
"inputs": [], | ||
"outputs": [ | ||
{ | ||
"components": [ | ||
{ | ||
"name": "hash", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"name": "expireAt", | ||
"type": "uint64" | ||
} | ||
], | ||
"name": "messages", | ||
"type": "tuple[]" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "upgrade", | ||
"inputs": [ | ||
{ | ||
"name": "newcode", | ||
"type": "cell" | ||
} | ||
], | ||
"outputs": [] | ||
}, | ||
{ | ||
"name": "constructor", | ||
"inputs": [], | ||
"outputs": [] | ||
} | ||
], | ||
"data": [], | ||
"events": [] | ||
} | ||
{"ABI version": 2, | ||
"header": ["time", "expire"], | ||
"functions": [ | ||
{ | ||
"name": "upgrade", | ||
"inputs": [ | ||
{"name":"newcode","type":"cell"} | ||
], | ||
"outputs": [ | ||
] | ||
}, | ||
{ | ||
"name": "sendTransaction", | ||
"inputs": [ | ||
{"name":"dest","type":"address"}, | ||
{"name":"value","type":"uint128"}, | ||
{"name":"bounce","type":"bool"} | ||
], | ||
"outputs": [ | ||
] | ||
}, | ||
{ | ||
"name": "getMessages", | ||
"inputs": [ | ||
], | ||
"outputs": [ | ||
{"components":[{"name":"hash","type":"uint256"},{"name":"expireAt","type":"uint64"}],"name":"messages","type":"tuple[]"} | ||
] | ||
}, | ||
{ | ||
"name": "constructor", | ||
"inputs": [ | ||
], | ||
"outputs": [ | ||
] | ||
} | ||
], | ||
"events": [ | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"public": "2ada2e65ab8eeab09490e3521415f45b6e42df9c760a639bcf53957550b25a16", | ||
"secret": "172af540e43a524763dd53b26a066d472a97c4de37d5498170564510608250c3" | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
{ | ||
"ABI version": 2, | ||
"version": "2.2", | ||
"header": ["time", "expire"], | ||
"functions": [ | ||
{ | ||
"name": "sendTransaction", | ||
"inputs": [ | ||
{"name":"dest","type":"address"}, | ||
{"name":"value","type":"uint128"}, | ||
{"name":"bounce","type":"bool"} | ||
], | ||
"outputs": [ | ||
] | ||
}, | ||
{ | ||
"name": "getMessages", | ||
"inputs": [ | ||
], | ||
"outputs": [ | ||
{"components":[{"name":"hash","type":"uint256"},{"name":"expireAt","type":"uint64"}],"name":"messages","type":"tuple[]"} | ||
] | ||
}, | ||
{ | ||
"name": "upgrade", | ||
"inputs": [ | ||
{"name":"newcode","type":"cell"} | ||
], | ||
"outputs": [ | ||
] | ||
}, | ||
{ | ||
"name": "constructor", | ||
"inputs": [ | ||
], | ||
"outputs": [ | ||
] | ||
} | ||
], | ||
"data": [ | ||
], | ||
"events": [ | ||
], | ||
"fields": [ | ||
{"name":"_pubkey","type":"uint256"}, | ||
{"name":"_constructorFlag","type":"bool"}, | ||
{"name":"m_messages","type":"map(uint256,uint32)"} | ||
] | ||
"ABI version": 2, | ||
"version": "2.2", | ||
"header": ["time", "expire"], | ||
"functions": [ | ||
{ | ||
"name": "sendTransaction", | ||
"inputs": [ | ||
{"name":"dest","type":"address"}, | ||
{"name":"value","type":"uint128"}, | ||
{"name":"bounce","type":"bool"} | ||
], | ||
"outputs": [ | ||
] | ||
}, | ||
{ | ||
"name": "getMessages", | ||
"inputs": [ | ||
], | ||
"outputs": [ | ||
{"components":[{"name":"hash","type":"uint256"},{"name":"expireAt","type":"uint64"}],"name":"messages","type":"tuple[]"} | ||
] | ||
}, | ||
{ | ||
"name": "upgrade", | ||
"inputs": [ | ||
{"name":"newcode","type":"cell"} | ||
], | ||
"outputs": [ | ||
] | ||
}, | ||
{ | ||
"name": "constructor", | ||
"inputs": [ | ||
], | ||
"outputs": [ | ||
] | ||
} | ||
], | ||
"data": [ | ||
], | ||
"events": [ | ||
], | ||
"fields": [ | ||
{"name":"_pubkey","type":"uint256"}, | ||
{"name":"_constructorFlag","type":"bool"}, | ||
{"name":"m_messages","type":"map(uint256,uint64)"} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"public": "2ada2e65ab8eeab09490e3521415f45b6e42df9c760a639bcf53957550b25a16", | ||
"secret": "172af540e43a524763dd53b26a066d472a97c4de37d5498170564510608250c3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
pragma ton-solidity >= 0.59.0; | ||
pragma AbiHeader time; | ||
pragma AbiHeader expire; | ||
|
||
abstract contract Upgradable { | ||
/* | ||
* Set code | ||
*/ | ||
|
||
function upgrade(TvmCell newcode) public virtual { | ||
require(msg.pubkey() == tvm.pubkey(), 101); | ||
tvm.accept(); | ||
tvm.commit(); | ||
tvm.setcode(newcode); | ||
tvm.setCurrentCode(newcode); | ||
onCodeUpgrade(); | ||
} | ||
|
||
function onCodeUpgrade() internal virtual; | ||
} | ||
|
||
contract GiverV3 is Upgradable { | ||
|
||
uint8 constant MAX_CLEANUP_MSGS = 30; | ||
mapping(uint256 => uint64) m_messages; | ||
|
||
modifier acceptOnlyOwner { | ||
require(msg.pubkey() == tvm.pubkey(), 101); | ||
tvm.accept(); | ||
_; | ||
} | ||
|
||
/* | ||
* Publics | ||
*/ | ||
|
||
/// @notice Allows to accept simple transfers. | ||
receive() external {} | ||
|
||
/// @notice Transfers grams to other contracts. | ||
function sendTransaction(address dest, uint128 value, bool bounce) public { | ||
dest.transfer(value, bounce, 3); | ||
gc(); | ||
} | ||
|
||
/* | ||
* Privates | ||
*/ | ||
|
||
/// @notice Function with predefined name called after signature check. Used to | ||
/// implement custom replay protection with parallel access. | ||
function afterSignatureCheck(TvmSlice body, TvmCell message) private inline | ||
returns (TvmSlice) | ||
{ | ||
// owner check | ||
require(msg.pubkey() == tvm.pubkey(), 101); | ||
// load and drop message timestamp (uint64) | ||
(, uint64 expireAt) = body.decode(uint64, uint32); | ||
require(expireAt > now, 57); | ||
uint256 msgHash = tvm.hash(message); | ||
require(!m_messages.exists(msgHash), 102); | ||
|
||
tvm.accept(); | ||
m_messages[msgHash] = expireAt; | ||
|
||
return body; | ||
} | ||
|
||
/// @notice Allows to delete expired messages from dict. | ||
function gc() private inline { | ||
uint counter = 0; | ||
for ((uint256 msgHash, uint64 expireAt) : m_messages) { | ||
if (counter >= MAX_CLEANUP_MSGS) { | ||
break; | ||
} | ||
counter++; | ||
if (expireAt <= now) { | ||
delete m_messages[msgHash]; | ||
} | ||
} | ||
} | ||
|
||
/* | ||
* Get methods | ||
*/ | ||
struct Message { | ||
uint256 hash; | ||
uint64 expireAt; | ||
} | ||
function getMessages() public view returns (Message[] messages) { | ||
for ((uint256 msgHash, uint64 expireAt) : m_messages) { | ||
messages.push(Message(msgHash, expireAt)); | ||
} | ||
} | ||
|
||
function onCodeUpgrade() internal override {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"public": "99c84f920c299b5d80e4fcce2d2054b05466ec9df19532a688c10eb6dd8d6b33", | ||
"secret": "73b60dc6a5b1d30a56a81ea85e0e453f6957dbfbeefb57325ca9f7be96d3fe1a" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
module.exports = { | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: 'tsconfig.json', | ||
globals: { | ||
"ts-jest": { | ||
tsconfig: "tsconfig.json", | ||
}, | ||
}, | ||
}, | ||
moduleFileExtensions: ['ts', 'js'], | ||
transform: { | ||
'^.+\\.(ts|tsx)$': 'ts-jest', | ||
}, | ||
testMatch: ['**/test/**/*.+(ts|js)', '**/__tests__/**/*.+(ts|tsx|js)'], | ||
testEnvironment: 'node', | ||
moduleFileExtensions: ["ts", "js"], | ||
transform: { | ||
"^.+\\.(ts|tsx)$": "ts-jest", | ||
}, | ||
modulePathIgnorePatterns: [".*\\.d\\.ts"], | ||
testMatch: ["**/test/**/*.+(ts)", "**/__tests__/**/*.+(ts|tsx)"], | ||
testEnvironment: "node", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.