public function announce(TxModel $transaction, KeyPair $kp = null)
    {
        // always set optional `signer` in case we provide a KeyPair
        if (null !== $kp) {
            $transaction->setAttribute("signer", $kp->getPublicKey("hex"));
        }

        // now we can serialize and sign
        $serialized = $transaction->serialize();
        $signature  = $this->signTransaction($transaction, $kp, $serialized);
        $broadcast  = [];

        if ($signature) {
            // valid KeyPair provided, signature was created.

            // recommended signed transaction broadcast method.
            // this will use the /transaction/announce endpoint.
            $broadcast = [
                "data" => Buffer::fromUInt8($serialized)->getHex(),
                "signature" => $signature->getHex(),
            ];
        }
        else {
            // WARNING: with this you must provide a `privateKey`
            // in the transaction attributes. This is *not* recommended.
            $broadcast = $transaction->toDTO();
        }

        $endpoint = $this->getAnnouncePath($transaction, $kp);
        $apiUrl   = $this->getPath($endpoint, []);
        $response = $this->api->postJSON($apiUrl, $broadcast);

        //XXX include Error checks
        $object = json_decode($response, true);
        return $this->createBaseModel($object); //XXX brr => error/content validation first
    }
public function announce(TxModel $transaction, KeyPair $kp = null)
    {
        // always set optional `signer` in case we provide a KeyPair
        if (null !== $kp) {
            $transaction->setAttribute("signer", $kp->getPublicKey("hex"));
        }

        // now we can serialize and sign
        $serialized = $transaction->serialize();
        $signature  = $this->signTransaction($transaction, $kp, $serialized);
        $broadcast  = [];

        if ($signature) {
            // valid KeyPair provided, signature was created.

            // recommended signed transaction broadcast method.
            // this will use the /transaction/announce endpoint.
            $broadcast = [
                "data" => Buffer::fromUInt8($serialized)->getHex(),
                "signature" => $signature->getHex(),
            ];
        }
        else {
            // WARNING: with this you must provide a `privateKey`
            // in the transaction attributes. This is *not* recommended.
            $broadcast = $transaction->toDTO();
        }

        $endpoint = $this->getAnnouncePath($transaction, $kp);
        $apiUrl   = $this->getPath($endpoint, []);
        $response = $this->api->postJSON($apiUrl, $broadcast);

        //XXX include Error checks
        $object = json_decode($response, true);
        return $this->createBaseModel($object); //XXX brr => error/content validation first
    }
public function announce ( TxModel $ transaction , KeyPair $ kp = null ) { // always set optional `signer` in case we provide a KeyPair if ( null !== $ kp ) { $ transaction -> setAttribute ( "signer" , $ kp -> getPublicKey ( "hex" ) ) ; } // now we can serialize and sign $ serialized = $ transaction -> serialize ( ) ; $ signature = $ this -> signTransaction ( $ transaction , $ kp , $ serialized ) ; $ broadcast = [ ] ; if ( $ signature ) { // valid KeyPair provided, signature was created. // recommended signed transaction broadcast method. // this will use the /transaction/announce endpoint. $ broadcast = [ "data" => Buffer :: fromUInt8 ( $ serialized ) -> getHex ( ) , "signature" => $ signature -> getHex ( ) , ] ; } else { // WARNING: with this you must provide a `privateKey` // in the transaction attributes. This is *not* recommended. $ broadcast = $ transaction -> toDTO ( ) ; } $ endpoint = $ this -> getAnnouncePath ( $ transaction , $ kp ) ; $ apiUrl = $ this -> getPath ( $ endpoint , [ ] ) ; $ response = $ this -> api -> postJSON ( $ apiUrl , $ broadcast ) ; //XXX include Error checks $ object = json_decode ( $ response , true ) ; return $ this -> createBaseModel ( $ object ) ; //XXX brr => error/content validation first }
Announce a transaction. The transaction will be serialized before
it is sent to the server.

Additionally, a KeyPair object can be passed to this method *if you wish
to have the transaction **signed locally** by the SDK instead of letting
the remote NIS sign for you*. The local signing method **is recommended**.

WARNING: In case you don't provide this method with a KeyPair,
you must provide a `privateKey` in the transaction attributes.
It is *not* recommended to send `privateKey` data over any network,
even local.

@param   \NEM\Models\Transaction     $transaction
@return  \NEM\Models\Model
Announce a transaction . The transaction will be serialized before it is sent to the server .