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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To NFT and Beyond

#### What Tokel offers:
- The blockchain that facilitates the tokens and NFTs.
- An open-sourced all-in-one ]GUI application](https://github.com/TokelPlatform/tokel_dapp).
- An open-sourced all-in-one [GUI application](https://github.com/TokelPlatform/tokel_dapp).
- DEX functionality for all tokens/NFTs created on Tokel.
- A free-to-use test blockchain (TKLTEST).
- Easy to use integrations (nSPV)
Expand Down Expand Up @@ -60,6 +60,7 @@ https://github.com/TokelPlatform/tokel_dapp
- Tokel Website: [https://tokel.io](https://tokel.io)
- Tokel Block Explorer: [https://explorer.tokel.io](https://explorer.tokel.io)
- Tokel Discord: [Tokel Discord Invitation](http://discord.tokel.io)
- Tokel Blog: [Tokel Blog](https://tokel.io/blog/)
- Email: [contact@tokel.io](mailto:contact@tokel.io)
- Whitepaper: [Tokel Paper](https://tokel.io/TokelPaper1stEdition.pdf)
- Knowledgebase & How-to: [Tokel Documentation](https://docs.tokel.io)
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dnl komodo codebase version
define(_KOMODO_VERSION, 60000)

dnl tokel codebase version
define(_TOKEL_VERSION, 30100)
define(_TOKEL_VERSION, 30200)

AC_DEFINE(KOMODO_VERSION, _KOMODO_VERSION, [Komodo Version])
AC_DEFINE(TOKEL_VERSION, _TOKEL_VERSION, [Tokel Version])
Expand Down
4 changes: 2 additions & 2 deletions qa/pytest_komodo/basic/pytest_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def mine_and_waitconfirms(txid, proxy, confs_req=2): # should be used after tx
try:
confirmations_amount = proxy.getrawtransaction(txid, 1)['confirmations']
if confirmations_amount < confs_req:
print("\ntx is not confirmed yet! Let's wait a little more")
print("\ntx is not confirmed yet! Let's wait a little more", txid, 'confs=', confirmations_amount, 'required=', confs_req)
time.sleep(5)
else:
print("\ntx confirmed")
Expand Down Expand Up @@ -249,7 +249,7 @@ def validate_tx_pattern(txid):
def validate_raddr_pattern(addr):
if not isinstance(addr, str):
return False
address_pattern = re.compile(r"R[a-zA-Z0-9]{33}\Z")
address_pattern = re.compile(r"[RC][a-zA-Z0-9]{33}\Z")
if address_pattern.match(addr):
return True
else:
Expand Down
3 changes: 3 additions & 0 deletions qa/pytest_komodo/basic/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ def test_getrawmempool(self, test_params):
res = rpc.getrawmempool(True)
assert res.get(txid).get('height') == kvheight

'''
# kv not supported
def test_kvsearch(self, test_params):
test_values = {
'key': 'search_key',
Expand All @@ -358,6 +360,7 @@ def test_kvsearch(self, test_params):
assert res.get('key') == test_values['key']
assert res.get('keylen') == keylen
assert res.get('value') == test_values['value']
'''

def test_notaries(self, test_params):
rpc = test_params.get('node1').get('rpc')
Expand Down
2 changes: 1 addition & 1 deletion qa/pytest_komodo/cc_modules/test_faucet.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class TestFaucetCCe2e:
def test_faucet_addresses(self, test_params):
rpc1 = test_params.get('node1').get('rpc')
pubkey = test_params.get('node1').get('pubkey')
address_pattern = re.compile(r"R[a-zA-Z0-9]{33}\Z") # normal R-addr
address_pattern = re.compile(r"[RC][a-zA-Z0-9]{33}\Z") # normal R-addr

res = rpc1.faucetaddress()
for key in res.keys():
Expand Down
2 changes: 1 addition & 1 deletion qa/pytest_komodo/cc_modules/test_heir.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class TestHeirFunc:
def test_heir_addresses(self, test_params):
rpc1 = test_params.get('node1').get('rpc')
pubkey = test_params.get('node2').get('pubkey')
address_pattern = re.compile(r"R[a-zA-Z0-9]{33}\Z") # normal R-addr
address_pattern = re.compile(r"[RC][a-zA-Z0-9]{33}\Z") # normal R-addr

# verify all keys look like valid AC addrs
res = rpc1.faucetaddress('')
Expand Down
5 changes: 3 additions & 2 deletions qa/pytest_komodo/cc_modules/test_oracles.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def test_oracles(test_params):

for x in result.keys():
if x.find('ddress') > 0:
assert result[x][0] == 'R'
assert result[x][0] == 'R' or result[x][0] == 'C'

result = rpc.oraclesaddress(pubkey)
assert_success(result)

for x in result.keys():
if x.find('ddress') > 0:
assert result[x][0] == 'R'
assert result[x][0] == 'R' or result[x][0] == 'C'

# there are no oracles created yet
if is_fresh_chain:
Expand Down Expand Up @@ -247,6 +247,7 @@ def test_oracles(test_params):

# checking data for s type
result = rpc.oraclessamples(globals()["oracle_{}".format("s")], batonaddr_s, "1")
print('result=', result)
assert "['Anton']" == str(result["samples"][0]['data'])

# checking data for S type
Expand Down
41 changes: 18 additions & 23 deletions qa/pytest_komodo/cc_modules/test_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,24 @@ def test_token(test_params):

for v in ["", "v2"] :

result = call_token_rpc(rpc, "token"+v+"address")
assert_success(result)
for x in result.keys():
if x.find('ddress') > 0:
assert result[x][0] == 'R'

result = call_token_rpc(rpc, "token"+v+"address", pubkey)
assert_success(result)
for x in result.keys():
if x.find('ddress') > 0:
assert result[x][0] == 'R'

result = call_token_rpc(rpc, "assetsaddress")
assert_success(result)
for x in result.keys():
if x.find('ddress') > 0:
assert result[x][0] == 'R'

result = call_token_rpc(rpc, "assetsaddress", pubkey)
assert_success(result)
for x in result.keys():
if x.find('ddress') > 0:
assert result[x][0] == 'R'
result = call_token_rpc(rpc, "token"+v+"indexkey", pubkey)
if v == '': # for v2 a diff result
assert_success(result)
for x in result.keys():
if x.find('ddress') > 0:
assert result[x][0] == 'R' or result[x][0] == 'C'
else : # v2 index keys:
for x in result:
assert x[0] == 'C'

result = call_token_rpc(rpc, "assets"+v+"indexkey", pubkey)
if v == '': # for v2 a diff result
assert_success(result)
for x in result.keys():
if x.find('ddress') > 0:
assert result[x][0] == 'R' or result[x][0] == 'C'
else : # v2 index key
assert result[0] == 'C'

# there are no tokens created yet
# TODO: this test conflicts with heir test because token creating for heir
Expand Down
6 changes: 3 additions & 3 deletions qa/pytest_komodo/cc_modules/test_unspentccundex.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def test_ccindex(test_params):
assert_success(result)
for x in result.keys():
if x.find('ddress') > 0:
assert result[x][0] == 'R'
assert result[x][0] == 'R' or result[x][0] == 'C'

# get token cc address for pubkey:
result = rpc.tokenaddress(pubkey)
assert_success(result)
pubkeyTokenCCAddress = ""
for x in result.keys():
if x.find('ddress') > 0:
assert result[x][0] == 'R'
assert result[x][0] == 'R' or result[x][0] == 'C'
if x == 'pubkey Tokens CC Address':
pubkeyTokenCCAddress = result[x]

Expand All @@ -46,7 +46,7 @@ def test_ccindex(test_params):
pubkey1TokenCCAddress = ""
for x in result.keys():
if x.find('ddress') > 0:
assert result[x][0] == 'R'
assert result[x][0] == 'R' or result[x][0] == 'C'
if x == 'pubkey Tokens CC Address':
pubkey1TokenCCAddress = result[x]

Expand Down
2 changes: 1 addition & 1 deletion qa/pytest_komodo/cc_modules/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def mine_and_waitconfirms(txid, proxy, confs_req=2): # should be used after tx
try:
confirmations_amount = proxy.getrawtransaction(txid, 1)['confirmations']
if confirmations_amount < confs_req:
print("\ntx is not confirmed yet! Let's wait a little more")
print("\ntx is not confirmed yet! Let's wait a little more", txid, 'confs=', confirmations_amount, 'required=', confs_req)
time.sleep(5)
else:
print("\ntx confirmed")
Expand Down
8 changes: 4 additions & 4 deletions src/cc/CCutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ bool _GetCCaddress(char *destaddr,uint8_t evalcode,CPubKey pk,bool mixed)
if (payoutCond.get() != 0 )
{
//if (mixed) CCtoAnon(payoutCond.get());
Getscriptaddress(destaddr,CCPubKey(payoutCond.get(), CC_MIXED_MODE_SUBVER_0));
Getscriptaddress(destaddr,CCPubKey(payoutCond.get(), mixed ? CC_MIXED_MODE_SUBVER_0 : CC_OLD_V1_SUBVER));
}
return(destaddr[0] != 0);
}
Expand All @@ -404,7 +404,7 @@ static bool _GetTokensCCaddress(char *destaddr, uint8_t evalcode1, uint8_t evalc
{
//if (mixed)
// CCtoAnon(payoutCond.get());
Getscriptaddress(destaddr, CCPubKey(payoutCond.get(), CC_MIXED_MODE_SUBVER_0));
Getscriptaddress(destaddr, CCPubKey(payoutCond.get(), mixed ? CC_MIXED_MODE_SUBVER_0 : CC_OLD_V1_SUBVER));
}
return(destaddr[0] != 0);
}
Expand All @@ -425,7 +425,7 @@ bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubK
if ( payoutCond.get() != 0 )
{
//if (mixed) CCtoAnon(payoutCond.get());
Getscriptaddress(destaddr,CCPubKey(payoutCond.get(), CC_MIXED_MODE_SUBVER_0));
Getscriptaddress(destaddr,CCPubKey(payoutCond.get(), mixed ? CC_MIXED_MODE_SUBVER_0 : CC_OLD_V1_SUBVER));
}
return(destaddr[0] != 0);
}
Expand All @@ -443,7 +443,7 @@ bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey
{
//if (mixed)
// CCtoAnon(payoutCond.get());
Getscriptaddress(destaddr, CCPubKey(payoutCond.get(), CC_MIXED_MODE_SUBVER_0));
Getscriptaddress(destaddr, CCPubKey(payoutCond.get(), mixed ? CC_MIXED_MODE_SUBVER_0 : CC_OLD_V1_SUBVER));
}
return(destaddr[0] != 0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cc/betprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ bool Eval::DisputePayout(AppVM &vm, std::vector<uint8_t> params, const CTransact
if (!GetTxConfirmed(disputeTx.vin[0].prevout.hash, sessionTx, sessionBlock))
return Error("couldnt-get-parent");

if (GetCurrentHeight() < sessionBlock.GetHeight() + waitBlocks)
if (GetCurrentHeightCompat() < sessionBlock.GetHeight() + waitBlocks)
return Invalid("dispute-too-soon"); // Not yet
}

Expand Down
2 changes: 1 addition & 1 deletion src/cc/disputepayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool Eval::DisputePayout(AppVM &vm, std::vector<uint8_t> params, const CTransact
if (!GetTxConfirmed(disputeTx.vin[0].prevout.hash, sessionTx, sessionBlock))
return Error("couldnt-get-parent");

if (GetCurrentHeight() < sessionBlock.GetHeight() + waitBlocks)
if (GetCurrentHeightCompat() < sessionBlock.GetHeight() + waitBlocks)
return Invalid("dispute-too-soon"); // Not yet
}

Expand Down
4 changes: 4 additions & 0 deletions src/cc/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ unsigned int Eval::GetCurrentHeight() const
{
return nCurrentHeight;
}
unsigned int Eval::GetCurrentHeightCompat() const
{
return chainActive.Height();
}

bool Eval::GetBlock(uint256 hash, CBlockIndex& blockIdx) const
{
Expand Down
1 change: 1 addition & 0 deletions src/cc/eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class Eval
virtual int64_t GetCurrentTime() const;
void SetCurrentTime(int64_t nTimeIn) { nCurrentTime = nTimeIn; }
virtual unsigned int GetCurrentHeight() const;
virtual unsigned int GetCurrentHeightCompat() const;
void SetCurrentHeight(int32_t nHeightIn) { nCurrentHeight = nHeightIn; }
virtual bool GetSpendsConfirmed(uint256 hash, std::vector<CTransaction> &spends) const;
virtual bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const;
Expand Down
2 changes: 1 addition & 1 deletion src/cc/oracles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ bool OraclesValidate(struct CCcontract_info* cp, Eval* eval, const CTransaction&
// vout.2: marker from oraclesfund tx to normal pubkey address (activation on Jul 15th 2019 00:00)
// vout.n-2: change, if any
// vout.n-1: opreturn with createtxid, pubkey and price per data point
if (GetLatestTimestamp(eval->GetCurrentHeight()) > PUBKEY_SPOOFING_FIX_ACTIVATION) {
if (GetLatestTimestamp(eval->GetCurrentHeightCompat()) > PUBKEY_SPOOFING_FIX_ACTIVATION) {
if (tx.vout.size() < 1 || DecodeOraclesOpRet(tx.vout.back().scriptPubKey, oracletxid, tmppk, amount) != 'R')
return eval->Invalid("invalid oraclesregister OP_RETURN data!");
else if (!eval->GetTxUnconfirmed(oracletxid, tmptx, hashblock))
Expand Down
2 changes: 1 addition & 1 deletion src/cc/rewards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t
if ( !CheckTxFee(tx, txfee, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime, dummy) )
return eval->Invalid("txfee is too high");
amount = vinTx.vout[0].nValue;
reward = RewardsCalc((int64_t)amount,tx.vin[0].prevout.hash,(int64_t)APR,(int64_t)minseconds,(int64_t)maxseconds,GetLatestTimestamp(eval->GetCurrentHeight()));
reward = RewardsCalc((int64_t)amount,tx.vin[0].prevout.hash,(int64_t)APR,(int64_t)minseconds,(int64_t)maxseconds,GetLatestTimestamp(eval->GetCurrentHeightCompat()));
if ( reward == 0 )
return eval->Invalid("no eligible rewards");
if ( numvins == 1 && tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 )
Expand Down
2 changes: 1 addition & 1 deletion src/cryptoconditions/src/cryptoconditions.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void asnCondition(const CC *cond, Condition_t *asn) {
default: return;
};
choice->cost = cc_getCost(cond);
choice->fingerprint.buf = calloc(1, fingerprintSize);
choice->fingerprint.buf = calloc(1, 32);
cond->type->fingerprint(cond, choice->fingerprint.buf);
choice->fingerprint.size = fingerprintSize;
}
Expand Down
4 changes: 4 additions & 0 deletions src/cryptoconditions/src/threshold.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ static CC *thresholdFromFulfillmentMixed(const Fulfillment_t *ffill) {

{ // Get the real threshold from the first ffill
CC *tc = fulfillmentToCC(arrFulfills[0], flags);
if (tc == NULL) {
free(cond);
return NULL;
}
if (tc->type->typeId != CC_Preimage || tc->preimageLength != 1) {
cc_free(tc);
free(cond);
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3897,6 +3897,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
std::vector<CScriptCheck> vChecks;
if (!ContextualCheckInputs(tx, state, view, fExpensiveChecks, flags, false, txdata[i], chainparams.GetConsensus(), consensusBranchId, pindex->GetBlockTime(), pindex->GetHeight(), evalcodeChecker, nScriptCheckThreads ? &vChecks : NULL))
return false;
control.Add(vChecks);
}

{ // check tx outputs including coinbases
Expand Down
16 changes: 10 additions & 6 deletions src/rpc/tokensrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,11 @@ static UniValue tokentransfer(const std::string& name, const UniValue& params, b
return MakeResultError("destination as address not active yet");
if (dest.which() != TX_PUBKEYHASH && dest.which() != TX_PUBKEY)
return MakeResultError("invalid destination pubkey or address");
if (V::EvalCode() == EVAL_TOKENS && dest.which() != TX_PUBKEY) // address not supported for tokens 1
return MakeResultError("invalid destination pubkey");

// after subver_1 upgrade only addresses always will be used as destination, pubkeys are converted to addresses
if (dest.which() == TX_PUBKEY && CCUpgrades::IsUpgradeActive(nTime, nHeight, CCUpgrades::GetUpgrades(), CCUpgrades::CCUPGID_MIXEDMODE_SUBVER_1))
// after subver_1 upgrade only addresses always will be used as destination, pubkeys are converted to addresses (for tokens v2)
if (V::EvalCode() == EVAL_TOKENSV2 && dest.which() == TX_PUBKEY && CCUpgrades::IsUpgradeActive(nTime, nHeight, CCUpgrades::GetUpgrades(), CCUpgrades::CCUPGID_MIXEDMODE_SUBVER_1))
dests.push_back(boost::get<CPubKey>(dest).GetID());
else
dests.push_back(dest); // address or pubkey
Expand Down Expand Up @@ -643,12 +645,14 @@ UniValue tokentransfermany(const std::string& name, const UniValue& params, bool
Myprivkey(mypriv);
std::vector<std::string> srctokenaddrs;
std::vector<std::pair<CCwrapper, uint8_t*>> probes;
if (V::IsMixed() == EVAL_TOKENS) {
if (V::EvalCode() == EVAL_TOKENS) {
CCwrapper probeCond;
probeCond.reset( MakeCCcond1(V::EvalCode(), mypk) );
char tokenaddr[KOMODO_ADDRESS_BUFSIZE];
GetTokensCCaddress(cpTokens, tokenaddr, mypk, V::IsMixed());
srctokenaddrs.push_back(tokenaddr);
//char tokenaddr[KOMODO_ADDRESS_BUFSIZE];
//GetTokensCCaddress(cpTokens, tokenaddr, mypk, V::IsMixed());
//srctokenaddrs.push_back(tokenaddr);
srctokenaddrs = GetTokenV1IndexKeys(mypk);

probes.push_back({probeCond, mypriv});

}
Expand Down
23 changes: 16 additions & 7 deletions src/test-komodo-cc/test-assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2873,15 +2873,24 @@ TEST_F(TestAssetsCC, tokenv2transfer_raddress)
EXPECT_TRUE(eval.AddTx(mcreatetx));
uint256 tokenid = mcreatetx.GetHash();

std::vector<CTxDestination> dests = { pk2 };
std::vector<CTxDestination> dests = { pk2.GetID() }; // dest R-address

std::vector<std::string> tokenaddrs = GetTokenV2IndexKeys(pk1);
CMutableTransaction mtransfertx = MakeTokenV2TransferTx(pk1, 0, tokenid, tokenaddrs, {}, 1, dests, 1, false, false);
ASSERT_FALSE(CTransaction(mtransfertx).IsNull());
EXPECT_TRUE(eval.AddTx(mtransfertx));
CAmount bal = TokenV2Balance(pk2, tokenid);
std::vector<std::string> tokenaddrs1 = GetTokenV2IndexKeys(pk1);
CMutableTransaction mtransfertx1 = MakeTokenV2TransferTx(pk1, 0, tokenid, tokenaddrs1, {}, 1, dests, 1, false, false);
ASSERT_FALSE(CTransaction(mtransfertx1).IsNull());
EXPECT_TRUE(eval.AddTx(mtransfertx1));
CAmount bal1 = TokenV2Balance(pk2, tokenid);
// std::cerr << __func__ << " TokenV2Balance(pk2, tokenid)=" << bal << " mtransfertxid=" << mtransfertx.GetHash().GetHex() << " reason=" << eval.state.GetRejectReason() << std::endl;
EXPECT_TRUE(bal == 1);
EXPECT_TRUE(bal1 == 1);

// try to spend
std::vector<std::string> tokenaddrs2 = GetTokenV2IndexKeys(pk2);
CMutableTransaction mtransfertx2 = MakeTokenV2TransferTx(pk2, 0, tokenid, tokenaddrs2, {}, 1, dests, 1, false, false);
ASSERT_FALSE(CTransaction(mtransfertx2).IsNull());
EXPECT_TRUE(eval.AddTx(mtransfertx2));
CAmount bal2 = TokenV2Balance(pk2, tokenid);
EXPECT_TRUE(bal2 == 1);

}

// test burn pk
Expand Down