Saltar al contenido principal

tx op agregar

Como se vio antes, puedes usar tuberías para pasar un sobre de transacción entre comandos. Antes solo hemos estado viendo transacciones con una operación, sin embargo, como se mencionó, puede haber hasta 100 operaciones en una sola transacción.

Para agregar una operación a una transacción, puedes usar el comando tx op agregar. Este comando toma el sobre de la transacción del comando anterior y le agrega una operación.

Considera un ejemplo más complicado. Considera emitir un activo, aquí USDC, con el requisito de que solo el emisor puede transferir fondos al distribuidor.


stellar keys generate --fund issuer
stellar keys generate --fund distributor

ISSUER_PK=$(stellar keys address issuer)

ASSET="USDC:$ISSUER_PK"

# Issue the asset by setting its options, establishing a trustline, and
# transferring the smallest amount possible to the distributor. Then
# deauthorize the distributor so that people can only send Claimable Balances,
# rather than transferring assets directly.

# first the issuer sets the options for being able to clawback and revoke the asset
stellar tx new set-options --fee 1000 --source issuer --set-clawback-enabled --set-revocable --build-only \
# next the distributor establishes a trustline with the asset. Note that here the distributor the source account for the operation, not the issuer
| stellar tx op add change-trust --op-source distributor --line $ASSET \
# then the issuer sends the smallest amount possible to the distributor
| stellar tx op add payment --destination distributor --asset $ASSET --amount 1 \
# finally the issuer deauthorizes the distributor from being able to send the asset
| stellar tx op add set-trustline-flags --asset $ASSET --trustor distributor --clear-authorize \
# Then both accounts need to sign the transaction
| stellar tx sign --sign-with-key issuer \
| stellar tx sign --sign-with-key distributor \
| stellar tx send

# Next is an example of sandwiching an operation. That is giving permission in one operation, preforming the operation, and then removing the permission in a third operation.
# Here is an example of minting new assets to the distributor with a sandwich transaction
# First authorize the distributor to receive the asset
stellar tx new set-trustline-flags --fee 1000 --build-only --source issuer --asset $ASSET --trustor $distributor_PK --set-authorize \
# Then mint the asset to the distributor
| stellar tx op add payment --destination distributor --asset $ASSET --amount 1_000_000_000_000 \
# Finally remove the authorization
| stellar tx op add set-trustline-flags --asset $ASSET --trustor distributor --clear-authorize \
| stellar tx sign --sign-with-key issuer \
| stellar tx send

Guías en esta categoría: