Skip to content

Commit

Permalink
Merge pull request #52 from haofengjiang/main
Browse files Browse the repository at this point in the history
mpc release rare satoshis
  • Loading branch information
CoboZhu authored Dec 28, 2023
2 parents 916a05d + bf417b1 commit 0c1fea5
Showing 1 changed file with 89 additions and 18 deletions.
107 changes: 89 additions & 18 deletions MPCClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function request(string $method, string $path, array $data)
$ch = curl_init();
$sorted_data = $this->sortData($data);
list($microsecond, $second) = explode(' ', microtime());
$nonce = (float)sprintf('%.0f', (floatval($microsecond) + floatval($second)) * 1000);
$nonce = (float) sprintf('%.0f', (floatval($microsecond) + floatval($second)) * 1000);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
Expand Down Expand Up @@ -179,6 +179,23 @@ function generateAddresses(string $chainCode, int $count)
return $this->request("POST", "/v1/custody/mpc/generate_addresses/", $params);
}

/***
* generate address
* string $chainCode
* string $address
* int $count
* @return mixed|string
*/
function generateAddressMemo(string $chainCode, string $address, int $count)
{
$params = [
"chain_code" => $chainCode,
"address" => $address,
"count" => $count,
];
return $this->request("POST", "/v1/custody/mpc/generate_address_memo/", $params);
}

/***
* update address description
* string $coin
Expand Down Expand Up @@ -308,18 +325,18 @@ function listSpendable(string $coin, string $address = null)
* BigInteger $feeAmount
* @return mixed|string
*/
function createTransaction(string $coin, string $requestId, BigInteger $amount = null, string $fromAddr = null,
string $toAddr = null, string $toAddressDetails = null, BigInteger $fee = null,
BigInteger $gasPrice = null, BigInteger $gasLimit = null, int $operation = null,
string $extraParameters = null, BigInteger $maxFee = null, BigInteger $maxPriorityFee = null,
BigInteger $feeAmount = null, string $remark = null, int $autoFuel = null)
function createTransaction(string $coin, string $requestId, BigInteger $amount = null, string $fromAddr = null,
string $toAddr = null, string $toAddressDetails = null, BigInteger $fee = null,
BigInteger $gasPrice = null, BigInteger $gasLimit = null, int $operation = null,
string $extraParameters = null, BigInteger $maxFee = null, BigInteger $maxPriorityFee = null,
BigInteger $feeAmount = null, string $remark = null, int $autoFuel = null, string $memo = null)
{
$params = [
"coin" => $coin,
"request_id" => $requestId,
];

if ($amount){
if ($amount) {
$params = array_merge($params, ["amount" => $amount->toString()]);
}
if ($fromAddr) {
Expand Down Expand Up @@ -361,6 +378,9 @@ function createTransaction(string $coin, string $requestId, BigInteger $amou
if ($autoFuel) {
$params = array_merge($params, ["auto_fuel" => $autoFuel]);
}
if ($memo) {
$params = array_merge($params, ["memo" => $memo]);
}

return $this->request("POST", "/v1/custody/mpc/create_transaction/", $params);
}
Expand All @@ -375,7 +395,7 @@ function createTransaction(string $coin, string $requestId, BigInteger $amou
* @return mixed|string
*/
function signMessage(string $chainCode, string $requestId, string $fromAddr,
int $signVersion, string $extraParameters)
int $signVersion, string $extraParameters)
{
$params = [
"chain_code" => $chainCode,
Expand All @@ -384,7 +404,7 @@ function signMessage(string $chainCode, string $requestId, string $fromAddr,
"sign_version" => $signVersion,
"extra_parameters" => $extraParameters,
];

return $this->request("POST", "/v1/custody/mpc/sign_message/", $params);
}

Expand All @@ -398,8 +418,8 @@ function signMessage(string $chainCode, string $requestId, string $fromAddr,
* BigInteger $feeAmount
* @return mixed|string
*/
function dropTransaction(string $coboId, string $requestId, string $fee = null, BigInteger $gasPrice = null,
BigInteger $gasLimit = null, BigInteger $feeAmount = null, int $autoFuel = null)
function dropTransaction(string $coboId, string $requestId, string $fee = null, BigInteger $gasPrice = null,
BigInteger $gasLimit = null, BigInteger $feeAmount = null, int $autoFuel = null)
{
$params = [
"cobo_id" => $coboId,
Expand Down Expand Up @@ -435,8 +455,8 @@ function dropTransaction(string $coboId, string $requestId, string $fee = nu
* BigInteger $feeAmount
* @return mixed|string
*/
function speedupTransaction(string $coboId, string $requestId, string $fee = null, BigInteger $gasPrice = null,
BigInteger $gasLimit = null, BigInteger $feeAmount = null, int $autoFuel = null)
function speedupTransaction(string $coboId, string $requestId, string $fee = null, BigInteger $gasPrice = null,
BigInteger $gasLimit = null, BigInteger $feeAmount = null, int $autoFuel = null)
{
$params = [
"cobo_id" => $coboId,
Expand Down Expand Up @@ -534,9 +554,9 @@ function transactionsByTxHash(string $txHash, int $transactionType = null)
* int $limit
* @return mixed|string
*/
function listTransactions(int $startTime = null, int $endTime = null, int $status = null, string $order = null,
string $order_by = null, int $transactionType = null, string $coins = null, string $fromAddress = null,
string $toAddress = null, int $limit = 50)
function listTransactions(int $startTime = null, int $endTime = null, int $status = null, string $order = null,
string $order_by = null, int $transactionType = null, string $coins = null, string $fromAddress = null,
string $toAddress = null, int $limit = 50)
{
$params = [
"limit" => $limit,
Expand Down Expand Up @@ -581,8 +601,8 @@ function listTransactions(int $startTime = null, int $endTime = null, int $st
* @return mixed|string
*/
function estimateFee(string $coin, BigInteger $amount = null, string $address = null, string $replaceCoboId = null, string $fromAddress = null,
string $toAddressDetails = null, string $fee = null, BigInteger $gasPrice = null, BigInteger $gasLimit = null,
string $extraParameters = null)
string $toAddressDetails = null, string $fee = null, BigInteger $gasPrice = null, BigInteger $gasLimit = null,
string $extraParameters = null)
{
$params = [
"coin" => $coin,
Expand Down Expand Up @@ -704,4 +724,55 @@ function getMaxSendAmount(string $coin, string $fee_rate, string $to_address, st

return $this->request("GET", "/v1/custody/mpc/get_max_send_amount/", $params);
}

/***
* lock spendable
* string $coin
* string $txHash
* int $voutN
*/
function lockSpendable(string $coin, string $txHash, int $voutN)
{
$params = [
"coin" => $coin,
"tx_hash" => $txHash,
"vout_n" => $voutN,
];

return $this->request("POST", "/v1/custody/mpc/lock_spendable/", $params);
}

/***
* unlock spendable
* string $coin
* string $txHash
* int $voutN
*/
function unlockSpendable(string $coin, string $txHash, int $voutN)
{
$params = [
"coin" => $coin,
"tx_hash" => $txHash,
"vout_n" => $voutN,
];

return $this->request("POST", "/v1/custody/mpc/unlock_spendable/", $params);
}

/***
* get rare satoshis
* string $coin
* string $txHash
* int $voutN
*/
function getRareSatoshis(string $coin, string $txHash, int $voutN)
{
$params = [
"coin" => $coin,
"tx_hash" => $txHash,
"vout_n" => $voutN,
];

return $this->request("GET", "/v1/custody/mpc/get_rare_satoshis/", $params);
}
}

0 comments on commit 0c1fea5

Please sign in to comment.