Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demo/NFTAuthDebot/build/NFTAuthDebot.abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ABI version":2,"version":"2.2","header":["pubkey","time","expire"],"functions":[{"name":"constructor","inputs":[{"name":"ownerPubkey","type":"uint256"},{"name":"nftIndexHelper","type":"address"},{"name":"collection","type":"address"},{"name":"nftList","type":"address[]"}],"outputs":[]},{"name":"start","inputs":[],"outputs":[]},{"name":"setUserWallet","inputs":[{"name":"value","type":"address"}],"outputs":[]},{"name":"checkOwnershipUseRoot","inputs":[],"outputs":[]},{"name":"getIndexCodeHash","inputs":[],"outputs":[]},{"name":"onGetCodeHashIndex","inputs":[{"name":"indexCodeHash","type":"uint256"}],"outputs":[]},{"name":"onGetIndexesByHash","inputs":[{"components":[{"name":"id","type":"address"},{"name":"data","type":"cell"}],"name":"accounts","type":"tuple[]"}],"outputs":[]},{"name":"checkIndexes","inputs":[],"outputs":[]},{"name":"checkIndexAccountStatus","inputs":[{"name":"acc_type","type":"int8"}],"outputs":[]},{"name":"checkIndexStatus","inputs":[{"name":"acc_type","type":"int8"}],"outputs":[{"name":"value0","type":"bool"}]},{"name":"onErrorGetCodeHashIndex","inputs":[{"name":"sdkError","type":"uint32"},{"name":"exitCode","type":"uint32"}],"outputs":[]},{"name":"checkOwnershipUseNfts","inputs":[],"outputs":[]},{"name":"getNftInfo","inputs":[],"outputs":[]},{"name":"onGetNftInfo","inputs":[{"name":"id","type":"uint256"},{"name":"owner","type":"address"},{"name":"manager","type":"address"},{"name":"collection","type":"address"}],"outputs":[]},{"name":"onErrorGetNftInfo","inputs":[{"name":"sdkError","type":"uint32"},{"name":"exitCode","type":"uint32"}],"outputs":[]},{"name":"foo","inputs":[],"outputs":[]},{"name":"authFailed","inputs":[],"outputs":[]},{"name":"getDebotInfo","id":"0xDEB","inputs":[],"outputs":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"publisher","type":"string"},{"name":"caption","type":"string"},{"name":"author","type":"string"},{"name":"support","type":"address"},{"name":"hello","type":"string"},{"name":"language","type":"string"},{"name":"dabi","type":"string"},{"name":"icon","type":"bytes"}]},{"name":"setIcon","inputs":[{"name":"icon","type":"bytes"}],"outputs":[]},{"name":"getRequiredInterfaces","inputs":[],"outputs":[{"name":"interfaces","type":"uint256[]"}]},{"name":"owner","inputs":[{"name":"answerId","type":"uint32"}],"outputs":[{"name":"pubkey","type":"uint256"}]},{"name":"transferOwnership","inputs":[{"name":"newOwner","type":"uint256"}],"outputs":[]},{"name":"getDebotOptions","inputs":[],"outputs":[{"name":"options","type":"uint8"},{"name":"debotAbi","type":"string"},{"name":"targetAbi","type":"string"},{"name":"targetAddr","type":"address"}]},{"name":"setABI","inputs":[{"name":"dabi","type":"string"}],"outputs":[]}],"data":[],"events":[{"name":"OwnershipTransferred","inputs":[{"name":"oldOwner","type":"uint256"},{"name":"newOwner","type":"uint256"}],"outputs":[]}],"fields":[{"name":"_pubkey","type":"uint256"},{"name":"_timestamp","type":"uint64"},{"name":"_constructorFlag","type":"bool"},{"name":"m_options","type":"uint8"},{"name":"m_debotAbi","type":"optional(string)"},{"name":"m_targetAbi","type":"optional(string)"},{"name":"m_target","type":"optional(address)"},{"name":"_owner","type":"uint256"},{"name":"_debotName","type":"string"},{"name":"_supportAddr","type":"address"},{"name":"_nftIndexHelper","type":"address"},{"name":"_nftList","type":"address[]"},{"name":"_collection","type":"address"},{"name":"_userAddr","type":"address"},{"name":"_lastCheckNftId","type":"uint128"},{"components":[{"name":"id","type":"address"},{"name":"data","type":"cell"}],"name":"_indexes","type":"tuple[]"},{"name":"_icon","type":"bytes"}]}
58 changes: 58 additions & 0 deletions demo/NFTAuthDebot/build/NFTAuthDebot.base64
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
te6ccgECYwEADL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LSAAGR1JJtAeLSAAGS+kCSbQHi1NHQ0//U+kDU0dD6QNMf9ARZbwIB1NHQ+kDU0dD6
QNN/0x/0BFlvAgHU0fh3+Hb4dfh0+HP4cvhx+HD4b/hu+G34bPhr+Gr4Y/hiAAr4RvLgTAIK9KQg
9KFiYQAUc29sIDAuNTguMQAA
Binary file added demo/NFTAuthDebot/build/NFTAuthDebot.tvc
Binary file not shown.
206 changes: 206 additions & 0 deletions demo/NFTAuthDebot/contracts/NFTAuthDebot.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
pragma ton-solidity = 0.58.1;
pragma AbiHeader expire;
pragma AbiHeader time;
pragma AbiHeader pubkey;

import "debot_imports/DeBot.sol";
import "debot_imports/Terminal.sol";
import "debot_imports/Sdk.sol";
import "debot_imports/Menu.sol";
import "debot_imports/UserInfo.sol";

import '@itgold/everscale-tip/contracts/access/OwnableExternal.sol';
import '@itgold/everscale-tip/contracts/TIP4_1/interfaces/ITIP4_1NFT.sol';

interface INFTIndexHelper {
function indexCodeHash(
address collection,
address owner
) external view responsible returns (uint256 indexCodeHash);
}

contract NFTAuthDebot is DeBot, OwnableExternal {

string _debotName = "Itgold NFT authentication deBot";
address _supportAddr = address.makeAddrStd(0, 0x5fb73ece6726d59b877c8194933383978312507d06dda5bcf948be9d727ede4b);

address _nftIndexHelper;
address[] _nftList;
address _collection;
address _userAddr;
uint128 _lastCheckNftId = 0;

AccData[] _indexes;

string constant _errorStr = "An error has occurred, please contact the developers";

bytes _icon;

constructor(
uint256 ownerPubkey,
address nftIndexHelper,
address collection,
address[] nftList
) OwnableExternal(ownerPubkey) public {
tvm.accept();

_nftIndexHelper = nftIndexHelper;
_collection = collection;
_nftList = nftList;
}

function start() public override {
UserInfo.getAccount(tvm.functionId(setUserWallet));
}

function setUserWallet(address value) public {
_userAddr = value;
checkOwnershipUseRoot();
}

function checkOwnershipUseRoot() public {
if (_collection.value != 0) {
getIndexCodeHash();
} else {
checkOwnershipUseNfts();
}
}

function getIndexCodeHash() public view {
optional(uint256) none;
INFTIndexHelper(_nftIndexHelper).indexCodeHash{
sign: false,
pubkey: none,
time: uint64(now),
expire: 0,
callbackId: onGetCodeHashIndex,
onErrorId: onErrorGetCodeHashIndex
}(_collection, _userAddr).extMsg;
}

function onGetCodeHashIndex(uint256 indexCodeHash) public {
Sdk.getAccountsDataByHash(
tvm.functionId(onGetIndexesByHash),
indexCodeHash,
address.makeAddrStd(0, 0)
);
}

function onGetIndexesByHash(AccData[] accounts) public {
_indexes = accounts;
checkIndexes();
}

function checkIndexes() public {
if(_indexes.length > 0) {
Sdk.getAccountType(tvm.functionId(checkIndexAccountStatus), _indexes[0].id);
}
else {
checkOwnershipUseNfts();
}
}

function checkIndexAccountStatus(int8 acc_type) public {
if (checkIndexStatus(acc_type)) {
foo();
} else {
_indexes[0] = _indexes[_indexes.length - 1];
_indexes.pop();
checkIndexes();
}
}

function checkIndexStatus(int8 acc_type) public returns(bool) {
if (acc_type == -1 || acc_type == 0 || acc_type == 2) {
return false;
} else {
return true;
}
}

function onErrorGetCodeHashIndex(uint32 sdkError, uint32 exitCode) public {
sdkError;exitCode; //disable warnings
checkOwnershipUseNfts();
}

function checkOwnershipUseNfts() public {
if (_nftList.length != 0) {
getNftInfo();
} else {
authFailed();
}
}

function getNftInfo() public view {
optional(uint256) none;
ITIP4_1NFT(_nftList[_lastCheckNftId]).getInfo{
sign: false,
pubkey: none,
time: uint64(now),
expire: 0,
callbackId: onGetNftInfo,
onErrorId: onErrorGetNftInfo
}().extMsg;
}

function onGetNftInfo(
uint256 id,
address owner,
address manager,
address collection
) public {
if (owner == _userAddr) {
foo();
} else {
if (_lastCheckNftId < _nftList.length - 1) {
_lastCheckNftId++;
getNftInfo();
} else {
authFailed();
}
}
}

function onErrorGetNftInfo(uint32 sdkError, uint32 exitCode) public {
sdkError;exitCode; //disable warnings
if (_lastCheckNftId < _nftList.length - 1) {
_lastCheckNftId++;
getNftInfo();
} else {
authFailed();
}
}

function foo() public {
Terminal.print(0, "Add the code here after successful authorization!");
}

function authFailed() public {
Terminal.print(0, "Forbitten! You don't have the right NFT");
}

function getDebotInfo() public functionID(0xDEB) override view returns(
string name, string version, string publisher, string caption, string author,
address support, string hello, string language, string dabi, bytes icon
) {
name = _debotName;
version = "0.9";
publisher = "https://itgold.io/";
caption = "Tip4 auth Debot";
author = "https://itgold.io/";
support = _supportAddr;
hello = "Hello, i'm itgold nft aithentication debot";
language = "en";
dabi = m_debotAbi.get();
icon = _icon;
}

function setIcon(bytes icon) public onlyOwner {
_icon = icon;
}

function getRequiredInterfaces() public view override returns (uint256[] interfaces) {
return [Sdk.ID, Terminal.ID, Menu.ID, UserInfo.ID];
}

}
55 changes: 55 additions & 0 deletions demo/NFTAuthDebot/contracts/debot_imports/DeBot.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
pragma ton-solidity >=0.35.0;
pragma AbiHeader expire;
pragma AbiHeader time;
pragma AbiHeader pubkey;

abstract contract DeBot {

uint8 constant DEBOT_ABI = 1;

uint8 m_options;
optional(string) m_debotAbi;
optional(string) m_targetAbi;
optional(address) m_target;

/*
* Public debot interface
*/

/// @notice DeBot entry point.
function start() public virtual;

/// @notice Returns DeBot metadata.
/// @return name String with name of debot, e.g. "DePool".
/// @return version Semver version of debot, that will be converted to string like "x.y.z".
/// @return publisher String with info about who has deployed debot to blokchain, e.g. "TON Labs".
/// @return caption (10-20 ch.) String with short description, e.g. "Work with Smthg".
/// @return author String with name of author of DeBot, e.g. "Ivan Ivanov".
/// @return support Free TON address of author for questions and donations.
/// @return hello String with first messsage with DeBot description.
/// @return language (ISO-639) String with debot interface language, e.g. "en".
/// @return dabi String with debot ABI.
function getDebotInfo() public functionID(0xDEB) view virtual returns(
string name, string version, string publisher, string caption, string author,
address support, string hello, string language, string dabi, bytes icon);

/// @notice Returns list of interfaces used by DeBot.
function getRequiredInterfaces() public view virtual returns (uint256[] interfaces);

/// @notice Returns DeBot ABI.
/// Deprecated.
function getDebotOptions() public view returns (uint8 options, string debotAbi, string targetAbi, address targetAddr) {
debotAbi = m_debotAbi.hasValue() ? m_debotAbi.get() : "";
targetAbi = m_targetAbi.hasValue() ? m_targetAbi.get() : "";
targetAddr = m_target.hasValue() ? m_target.get() : address(0);
options = m_options;
}

/// @notice Allow to set debot ABI. Do it before using debot.
function setABI(string dabi) public {
require(tvm.pubkey() == msg.pubkey(), 100);
tvm.accept();
m_options |= DEBOT_ABI;
m_debotAbi = dabi;
}
}
30 changes: 30 additions & 0 deletions demo/NFTAuthDebot/contracts/debot_imports/Menu.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
pragma ton-solidity >=0.35.0;

struct MenuItem {
string title;
string description;
uint32 handlerId;
}

interface IMenu {

function select(string title, string description, MenuItem[] items) external returns (uint32 index);

}

library Menu {

uint256 constant ID = 0xac1a4d3ecea232e49783df4a23a81823cdca3205dc58cd20c4db259c25605b48;
int8 constant DEBOT_WC = -31;

function select(string title, string description, MenuItem[] items) public pure {
address addr = address.makeAddrStd(DEBOT_WC, ID);
IMenu(addr).select(title, description, items);
}
}

contract MenuABI is IMenu {

function select(string title, string description, MenuItem[] items) external override returns (uint32 index) {}

}
Loading