Merge branch 'dev' into jl777
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
# MigrateCoin protocol
|
||||
|
||||
|
||||
|
||||
## ExportCoins tx:
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
vin:
|
||||
|
||||
[ any ]
|
||||
|
||||
vout:
|
||||
|
||||
- amount: {burnAmount}
|
||||
|
||||
script: OP_RETURN "send to ledger {id} {voutsHash}"
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
* ExportCoin is a standard tx which burns coins in an OP_RETURN
|
||||
|
||||
|
||||
|
||||
## ImportCoins tx:
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
vin:
|
||||
|
||||
- txid: 0000000000000000000000000000000000000000000000000000000000000000
|
||||
|
||||
idx: 0
|
||||
|
||||
script: CC_EVAL(EVAL_IMPORTCOINS, {momoProof},{exportCoin}) OP_CHECKCRYPTOCONDITION_UNILATERAL
|
||||
|
||||
vout:
|
||||
|
||||
- [ vouts matching voutsHash in exportCoin ]
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
* ImportCoin transaction has no signature
|
||||
|
||||
* ImportCoin is non malleable
|
||||
|
||||
* ImportCoin satisfies tx.IsCoinBase()
|
||||
|
||||
* ImportCoin uses a new opcode which allows a one sided check (no scriptPubKey)
|
||||
|
||||
* ImportCoin must contain CC opcode EVAL_IMPORTCOINS
|
||||
|
||||
* ImportCoin fees are equal to the difference between burnAmount in exportCoins and the sum of outputs.
|
||||
43
migratecoin.sh
Normal file
43
migratecoin.sh
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# This script makes the neccesary transactions to migrate
|
||||
# coin between 2 assetchains on the same -ac_cc id
|
||||
|
||||
set -e
|
||||
|
||||
source=TXSCL
|
||||
target=TXSCL000
|
||||
address="RFw7byY4xZpZCrtkMk3nFuuG1NTs9rSGgQ"
|
||||
amount=1
|
||||
|
||||
# Alias for running cli on source chain
|
||||
cli_source="komodo-cli -ac_name=$source"
|
||||
|
||||
# Raw tx that we will work with
|
||||
txraw=`$cli_source createrawtransaction "[]" "{\"$address\":$amount}"`
|
||||
|
||||
# Convert to an export tx
|
||||
exportData=`$cli_source migrate_converttoexport $txraw $target $amount`
|
||||
exportRaw=`echo $exportData | jq -r .exportTx`
|
||||
exportPayouts=`echo $exportData | jq -r .payouts`
|
||||
|
||||
# Fund
|
||||
exportFundedData=`$cli_source fundrawtransaction $exportRaw`
|
||||
exportFundedTx=`echo $exportFundedData | jq -r .hex`
|
||||
|
||||
# Sign
|
||||
exportSignedData=`$cli_source signrawtransaction $exportFundedTx`
|
||||
exportSignedTx=`echo $exportSignedData | jq -r .hex`
|
||||
|
||||
# Send
|
||||
echo "Sending export tx"
|
||||
$cli_source sendrawtransaction $exportSignedTx
|
||||
|
||||
read -p "Wait for a notarisation to KMD, and then two more notarisations from the target chain, and then press enter to continue"
|
||||
|
||||
# Create import
|
||||
importTx=`$cli_source migrate_createimporttransaction $exportSignedTx $payouts`
|
||||
importTx=`komodo-cli migrate_completeimporttransaction $importTx`
|
||||
|
||||
# Send import
|
||||
komodo-cli -ac_name=$target sendrawtransaction $importTx
|
||||
@@ -59,7 +59,7 @@ bool Eval::ImportCoin(const std::vector<uint8_t> params, const CTransaction &imp
|
||||
|
||||
// check burn amount
|
||||
{
|
||||
uint64_t burnAmount = burnTx.vout[0].nValue;
|
||||
uint64_t burnAmount = burnTx.vout.back().nValue;
|
||||
if (burnAmount == 0)
|
||||
return Invalid("invalid-burn-amount");
|
||||
uint64_t totalOut = 0;
|
||||
|
||||
@@ -50,6 +50,8 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh
|
||||
|
||||
int seenOwnNotarisations = 0;
|
||||
|
||||
bool txscl = IsTXSCL(symbol);
|
||||
|
||||
for (int i=0; i<NOTARISATION_SCAN_LIMIT_BLOCKS; i++) {
|
||||
if (i > kmdHeight) break;
|
||||
NotarisationsInBlock notarisations;
|
||||
@@ -72,8 +74,9 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh
|
||||
|
||||
if (seenOwnNotarisations == 1) {
|
||||
BOOST_FOREACH(Notarisation& nota, notarisations) {
|
||||
if (nota.second.ccId == targetCCid)
|
||||
moms.push_back(nota.second.MoM);
|
||||
if (IsTXSCL(nota.second.symbol) == txscl)
|
||||
if (nota.second.ccId == targetCCid)
|
||||
moms.push_back(nota.second.MoM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint
|
||||
{
|
||||
std::vector<uint8_t> burnOpret;
|
||||
if (burnTx.vout.size() == 0) return false;
|
||||
GetOpReturnData(burnTx.vout[0].scriptPubKey, burnOpret);
|
||||
GetOpReturnData(burnTx.vout.back().scriptPubKey, burnOpret);
|
||||
return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid);
|
||||
ss >> targetSymbol;
|
||||
ss >> payoutsHash);
|
||||
@@ -61,7 +61,7 @@ CAmount GetCoinImportValue(const CTransaction &tx)
|
||||
CTransaction burnTx;
|
||||
std::vector<CTxOut> payouts;
|
||||
if (UnmarshalImportTx(tx, proof, burnTx, payouts)) {
|
||||
return burnTx.vout.size() ? burnTx.vout[0].nValue : 0;
|
||||
return burnTx.vout.size() ? burnTx.vout.back().nValue : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
17
src/main.cpp
17
src/main.cpp
@@ -1552,14 +1552,17 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
|
||||
KOMODO_ON_DEMAND++;
|
||||
pool.addUnchecked(hash, entry, !IsInitialBlockDownload());
|
||||
|
||||
// Add memory address index
|
||||
if (fAddressIndex) {
|
||||
pool.addAddressIndex(entry, view);
|
||||
}
|
||||
if (!tx.IsCoinImport())
|
||||
{
|
||||
// Add memory address index
|
||||
if (fAddressIndex) {
|
||||
pool.addAddressIndex(entry, view);
|
||||
}
|
||||
|
||||
// Add memory spent index
|
||||
if (fSpentIndex) {
|
||||
pool.addSpentIndex(entry, view);
|
||||
// Add memory spent index
|
||||
if (fSpentIndex) {
|
||||
pool.addSpentIndex(entry, view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ NotarisationsInBlock ScanBlockNotarisations(const CBlock &block, int nHeight)
|
||||
{
|
||||
NotarisationData data;
|
||||
if (ParseNotarisationOpReturn(tx, data))
|
||||
if (strlen(data.symbol) >= 5 && strncmp(data.symbol, "TXSCL", 5) == 0)
|
||||
if (IsTXSCL(data.symbol))
|
||||
isTxscl = 1;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,11 @@ NotarisationsInBlock ScanBlockNotarisations(const CBlock &block, int nHeight)
|
||||
return vNotarisations;
|
||||
}
|
||||
|
||||
bool IsTXSCL(const char* symbol)
|
||||
{
|
||||
return strlen(symbol) >= 5 && strncmp(symbol, "TXSCL", 5) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool GetBlockNotarisations(uint256 blockHash, NotarisationsInBlock &nibs)
|
||||
{
|
||||
|
||||
@@ -24,5 +24,6 @@ bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n);
|
||||
void WriteBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch);
|
||||
void EraseBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch);
|
||||
int ScanNotarisationsDB(int height, std::string symbol, int scanLimitBlocks, Notarisation& out);
|
||||
bool IsTXSCL(const char* symbol);
|
||||
|
||||
#endif /* NOTARISATIONDB_H */
|
||||
|
||||
@@ -180,7 +180,7 @@ TEST_F(TestCoinImport, testInvalidBurnOutputs)
|
||||
|
||||
TEST_F(TestCoinImport, testInvalidBurnParams)
|
||||
{
|
||||
burnTx.vout[0].scriptPubKey = CScript() << OP_RETURN << E_MARSHAL(ss << VARINT(testCcid));
|
||||
burnTx.vout.back().scriptPubKey = CScript() << OP_RETURN << E_MARSHAL(ss << VARINT(testCcid));
|
||||
MoMoM = burnTx.GetHash(); // TODO: an actual branch
|
||||
CTransaction tx = MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts);
|
||||
TestRunCCEval(tx);
|
||||
@@ -198,7 +198,7 @@ TEST_F(TestCoinImport, testWrongChainId)
|
||||
|
||||
TEST_F(TestCoinImport, testInvalidBurnAmount)
|
||||
{
|
||||
burnTx.vout[0].nValue = 0;
|
||||
burnTx.vout.back().nValue = 0;
|
||||
MoMoM = burnTx.GetHash(); // TODO: an actual branch
|
||||
CTransaction tx = MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts);
|
||||
TestRunCCEval(tx);
|
||||
|
||||
Reference in New Issue
Block a user