Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocol 13 support #317

Merged
merged 9 commits into from
Apr 13, 2020
Merged

Protocol 13 support #317

merged 9 commits into from
Apr 13, 2020

Conversation

abuiles
Copy link
Contributor

@abuiles abuiles commented Apr 7, 2020

What

Add protocol 13 support with backwards compatibility support for protocol 12.

Why

In order to provide a seamless transition between protocol 12 and 13, we need to release a new version of the SDK that can read and generate transactions which will work in both protocols.

This pull request:

  • Updates the XDR definitions with protocol 13.
  • Extends Transaction to work with TransactionV1Envelope and TransactionV0Envelope.
  • Generates TransactionEnvelope which can be read by protocol 12 or protocol 13.
  • Reads TransactionEnvelope generated by protocol 12 or protocol 13.
  • Adds backward compatibility support for CAP0018
  • Adds partial support for CAP0015.
    • The Transaction class which offers an abstraction around xdr.Transaction doesn't support FeeBumpTransaction yet, however, consumers of this library can create and read fee bump transactions using xdr.FeeBumpTransaction.

Fix #320

Breaking changes

  • If you are only relying on the high level methods of this library, upgrading to the new version of the library should not bring any breaking changes.
  • If you are relying on xdr.TransactionEnvelope or transaction.toEnvelope() then there are breaking changes and you'll have to update your code to match the new API around xdr.TransactionEnvelope.

@abuiles abuiles force-pushed the protocol-13 branch 3 times, most recently from 6965206 to dc13c20 Compare April 7, 2020 22:07
@abuiles abuiles changed the base branch from master to release-v3.0.0 April 10, 2020 14:27
@abuiles abuiles marked this pull request as ready for review April 10, 2020 15:08
@abuiles abuiles requested review from 2opremio, tamirms, ire-and-curses and a team April 10, 2020 15:21
src/transaction.js Show resolved Hide resolved
src/transaction.js Show resolved Hide resolved
test/unit/transaction_test.js Show resolved Hide resolved
src/transaction_builder.js Outdated Show resolved Hide resolved
Copy link
Member

@ire-and-curses ire-and-curses left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this in a call, looks good with small fixes added.

src/transaction_builder.js Outdated Show resolved Hide resolved
@abuiles abuiles merged commit da314ec into release-v3.0.0 Apr 13, 2020
@@ -333,7 +333,8 @@ export namespace Operation {
interface AllowTrust extends BaseOperation<OperationType.AllowTrust> {
trustor: string;
assetCode: string;
authorize: boolean | undefined;
// this is a boolean or a number so that it can support protocol 12 or 13
authorize: boolean | number | undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ire-and-curses @tamirms I'll actually do the same for this, add the breaking change, making it a number.

abuiles added a commit that referenced this pull request Apr 20, 2020
* Update XDR definitions.

* Fix hash generation with v1 or v0 transactions.

* Pass networkPassphrase.

* Fix transaction envelope for TransactionV1Envelope.

* Fix more transaction related tests.

* Update type for allowTrust.

* Fix test for authorize.

* Build a TransactionV0.

* Add comment on TS types.
@abuiles abuiles mentioned this pull request Apr 27, 2020
abuiles added a commit that referenced this pull request Apr 27, 2020
This version brings protocol 13 support with backwards compatibility support for protocol 12.

### Add
- Add `TransactionBuilder.buildFeeBumpTransaction` which makes it easy to create `FeeBumpTransaction` ([#321](#321)).
- Adds a feature flag which allow consumers of this library to create V1 (protocol 13) transactions using the `TransactionBuilder` ([#321](#321)).
- Add support for [CAP0027](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0027.md): First-class multiplexed accounts ([#325](#325)).
- Add `Keypair.xdrMuxedAccount` which creates a new `xdr.MuxedAccount`([#325](#325)).
- Add `FeeBumpTransaction` which makes it easy to work with fee bump transactions ([#328](#328)).
- Add `TransactionBuilder.fromXDR` which receives an xdr envelope and return a `Transaction` or `FeeBumpTransaction` ([#328](#328)).

### Update
- Update XDR definitions with protocol 13 ([#317](#317)).
- Extend `Transaction` to work with `TransactionV1Envelope` and `TransactionV0Envelope` ([#317](#317)).
- Add backward compatibility support for [CAP0018](https://github.com/stellar/stellar-protocol/blob/f01c9354aaab1e8ca97a25cf888829749cadf36a/core/cap-0018.md) ([#317](#317)).
- Update operations builder to support multiplexed accounts ([#337](#337)).

  This allows you to specify an `M` account as the destination or source:
  ```
  var destination = 'MAAAAAAAAAAAAAB7BQ2L7E5NBWMXDUCMZSIPOBKRDSBYVLMXGSSKF6YNPIB7Y77ITLVL6';
  var amount = '1000.0000000';
  var asset = new StellarBase.Asset(
    'USDUSD',
    'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7'
  );
  var source =
    'MAAAAAAAAAAAAAB7BQ2L7E5NBWMXDUCMZSIPOBKRDSBYVLMXGSSKF6YNPIB7Y77ITLVL6';
  StellarBase.Operation.payment({
    destination,
    asset,
    amount,
    source
  });
  ```

  **To use multiplexed accounts you need an instance of Stellar running on Protocol 13 or higher**

### Breaking changes

- `Transaction.toEnvelope()` returns a protocol 13 `xdr.TransactionEnvelope` which is an `xdr.Union` ([#317](#317)).
  If you have code that looks like this `transaction.toEnvelope().tx` you have two options:
    - You can grab the value wrapped by the union, calling `value()` like `transaction.toEnvelope().value().tx`.
    - You can check which is the discriminant by using `switch()` and then call `v0()`, `v1()`, or `feeBump()`.
- The return value from `Transaction.fee` changed from `number` to `string`. This brings support for `Int64` values ([#321](#321)).
- The const `BASE_FEE` changed from `number` to `string` ([#321](#321)).
- The option `fee` passed to  `new TransactionBuilder({fee: ..})` changed from `number` to `string` ([#321](#321)).
- The following fields, which were previously an `xdr.AccountID` are now a  `xdr.MuxedAccount` ([#325](#325)):
  - `PaymentOp.destination`
  - `PathPaymentStrictReceiveOp.destination`
  - `PathPaymentStrictSendOp.destination`
  - `Operation.sourceAccount`
  - `Operation.destination` (for `ACCOUNT_MERGE`)
  - `Transaction.sourceAccount`
  - `FeeBumpTransaction.feeSource`

  You can get the string representation by calling `StrKey.encodeMuxedAccount` which will return a `G..` or `M..` account.
- Remove the following deprecated functions ([#331](#331)):
  - `Operation.manageOffer`
  - `Operation.createPassiveOffer`
  - `Operation.pathPayment`
  - `Keypair.fromBase58Seed`
- Remove the `Network` class ([#331](#331)).
- Remove `vendor/base58.js` ([#331](#331)).
@Shaptic Shaptic deleted the protocol-13 branch June 13, 2023 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants