Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use process tx in bitcoin #71

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
35 changes: 35 additions & 0 deletions contracts/btfd/QpErc20Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,41 @@ contract QpErc20Token is Initializable, ContextUpgradeable, TokenReceivableUpgra
emit TransactionProcessed(miner, blocknumber, txid, timestamp);
}

function processTx(
bytes32 txid) public {

(uint64 block,
uint64 timestamp,
BtcLib.TransferItem[] memory inputs,
BtcLib.TransferItem[] memory outputs,
bytes memory encodedCall) = // includes targetNetwork, beneficiary, targetContract, methodCall, fee
BtcLib.retrieveTx(blocknumber, txid);

QpErc20Storage storage $ = _getQPERC20Storage();
if ($.processedTxs[txid] != 0) revert TxAlreadyProcessed();
inputs = preProcessValues(inputs);
values = preProcessValues(values);

if (froms.length == 0) {
for (uint i = 0; i < tos.length; i++) {
// this is a mint
_mintBtc(tos[i], values[i]);
}
} else {
uint sum_inputs;
for (uint i = 0; i < froms.length; i++) {
// this is a transfer to the contract
_transferBtc(froms[i], address(this), inputs[i]);
sum_inputs += inputs[i];
}
processMultiTransferOutputs(txid, tos, values, sum_inputs, remoteCall);
}

address miner = msg.sender;
$.processedTxs[txid] = blocknumber;
emit TransactionProcessed(miner, blocknumber, txid, timestamp);
}

function processMultiTransferOutputs(
bytes32 txid,
address[] memory tos,
Expand Down