feat: autotransfer

This commit is contained in:
hashbro
2026-08-17 02:03:17 +08:00
parent 376b442880
commit a32043df71
42 changed files with 3268 additions and 256 deletions
+26 -2
View File
@@ -28,8 +28,20 @@ class TronDriver implements ChainDriver
$derived = Bip44::derive($mnemonic, $this->path($index));
$from = TronAddress::fromUncompressedPublicKey($derived['public_key_uncompressed']);
$sun = $this->toSun($amount);
return $this->sendNativeWithPrivateKey($derived['private_key'], $from, $to, $amount);
}
/**
* Send TRX using a raw private key (fee top-up wallet).
*/
public function sendNativeWithPrivateKey(string $privateKeyHex, string $from, string $to, string $amount): string
{
if (! $this->isValidAddress($from) || ! $this->isValidAddress($to)) {
throw new RuntimeException('Invalid Tron address');
}
$sun = $this->toSun($amount);
$tx = $this->post('/wallet/createtransaction', [
'owner_address' => $from,
'to_address' => $to,
@@ -37,7 +49,19 @@ class TronDriver implements ChainDriver
'visible' => true,
]);
return $this->signAndBroadcast($tx, $derived['private_key']);
return $this->signAndBroadcast($tx, $privateKeyHex);
}
public static function addressFromPrivateKey(string $privateKeyHex): string
{
$privateKeyHex = strtolower(trim($privateKeyHex));
if (str_starts_with($privateKeyHex, '0x')) {
$privateKeyHex = substr($privateKeyHex, 2);
}
$ec = new \Elliptic\EC('secp256k1');
$pub = $ec->keyFromPrivate($privateKeyHex)->getPublic(false, 'hex');
return TronAddress::fromUncompressedPublicKey($pub);
}
public function sendToken(string $mnemonic, int $index, string $to, string $amount, string $contract): string