Skip to content

Instantly share code, notes, and snippets.

@crcrcr999
Last active July 1, 2021 11:08
Show Gist options
  • Save crcrcr999/142f4386bef7dc31a8c6ee67249b54bb to your computer and use it in GitHub Desktop.
Save crcrcr999/142f4386bef7dc31a8c6ee67249b54bb to your computer and use it in GitHub Desktop.
XCH(chia) getCoinId by PHP
<?php
function hexToStr($hex){
$string='';
for ($i=0; $i < strlen($hex)-1; $i+=2){
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}
function getCoinId($parent_coin_info,$puzzle_hash,$amount){
$coinId='';
$amountHex=dechex($amount);
while(strlen($amountHex)%2>0){
$amountHex='0'.$amountHex;
}
if(!is_numeric(substr($amountHex,0,1))){
$amountHex='00'.$amountHex;
}
$coinId=hash('sha256', hexToStr($parent_coin_info.$puzzle_hash.$amountHex));
return $coinId;
}
$coinid=getCoinId('ccd5bb71183532bff220ba46c268991a00000000000000000000000000000000','d23da14695a188ae5708dd152263c4db883eb27edeb936178d4d988b8f3ce5fc',18375000000000000000);
echo 'coinId值:'.$coinid;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment