crypto = $crypto; $this->signer = $signer; } public function marketing( int $campaign, string $adType, string $keyword, string $displayed, int $impressions, int $clicks, int $impressionValue, int $clickValue, string $advertiser, int $fee, ?int $timestamp = null, ): SignedTransaction { $timestamp ??= time(); $adType = Binary::fixedText($adType, 6, 'Ad type'); $keyword = Binary::fixedText($keyword, 40, 'Marketing keyword'); $displayed = Binary::fixedText($displayed, 100, 'Display location'); $unsigned = [ 'txtype' => 5, 'time' => $timestamp, 'campaign' => $campaign, 'ad_type' => $adType, 'keyword' => $keyword, 'displayed' => $displayed, 'impression' => $impressions, 'click' => $clicks, 'impression_value' => $impressionValue, 'click_value' => $clickValue, 'advertiser' => $advertiser, 'txfee' => $fee, ]; $binary = Binary::u8(5) . Binary::u32($timestamp) . Binary::u64($campaign) . $adType . $keyword . $displayed . Binary::u8($impressions) . Binary::u8($clicks) . Binary::u16($impressionValue) . Binary::u16($clickValue) . Address::toBytes($advertiser) . Binary::u64($fee); return $this->sign($unsigned, $binary); } public function collateralClaim( string $contractHash, string $address, int $fee, ?int $timestamp = null, ): SignedTransaction { $timestamp ??= time(); $unsigned = [ 'txtype' => 9, 'time' => $timestamp, 'contract_hash' => $contractHash, 'address' => $address, 'txfee' => $fee, ]; $binary = Binary::u8(9) . Binary::u32($timestamp) . RequestBuilder::hash($contractHash, 'Loan contract hash') . Address::toBytes($address) . Binary::u64($fee); return $this->sign($unsigned, $binary); } public function loanPayment( int $amount, string $contractHash, string $address, int $tip, int $fee, ?int $timestamp = null, ): SignedTransaction { $timestamp ??= time(); $unsigned = [ 'txtype' => 8, 'timestamp' => $timestamp, 'payback_amount' => $amount, 'contract_hash' => $contractHash, 'address' => $address, 'tip' => $tip, 'txfee' => $fee, ]; $json = json_encode( $unsigned, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_PRESERVE_ZERO_FRACTION, ); $hash = $this->crypto->skein256($json); $signature = $this->signer->sign($hash); $binary = Binary::u8(8) . Binary::u32($timestamp) . Binary::u64($amount) . RequestBuilder::hash($contractHash, 'Loan contract hash') . Address::toBytes($address) . Binary::u64($tip) . Binary::u64($fee) . $hash . $signature; return new SignedTransaction($binary, $signature, $json); } }