Unverified Commit bd14e848 authored by Amaury Martiny's avatar Amaury Martiny Committed by GitHub
Browse files

refactor!: Pass mandatory registry everywhere (#141)

BREAKING CHANGE:

This refactor breaks compatibility with v1, as all functions now require a `{ metadataRpc?, registry }` last argument.

#### Rationale

In v1, by not passing any last argument, we implicitly used Kusama's most recent TypeRegistry. This was a handy shortcut, but might create hard-to-debug issues down the road (e.g. using another chain, or using Kusama with an incompatible spec version).

In v2, we never default to Kusama anymore, and always require the user passing the registry (and sometimes the metadata too, if needed, see docs for details).

Example 1:

```diff
+ // Get Kusama's registry at `specVersion`
+ const registry = getRegistry('Kusama', 'kusama', specVersion);

const unsigned = methods.balances.transfer(
  { dest: '1F...', value: 23 },
  {
    // other info about tx
-    metadataRpc: metadataRpc,
- }
+  }, {
+    metadataRpc: metadataRpc,
+    registry: registry
+  }
);
```

Example 2:

```diff
const unsigned = {...};
const signature = '...';

+ // Get Kusama's registry at `specVersion`
+ const registry = getRegistry('Kusama', 'kusama', unsigned.specVersion);

- const signed = createSigned(unsigned, signature);
+ const signed = createSigned(unsigned, signature, {
+    metadataRpc: unsigned.metadata,
+    registry,
+ });
```

Here is the full list of breaking changes:
- `decode` function taking 3 arguments was deprecated in v1, in favor or 2 arguments. In v2, `decode` takes exactly 2 arguments.
- `createSigningPayload`, `createSignedTx`, `methods.*.*` functions all take a mandatory last argument `{ metadataRpc?, registry }`. Note that the `metadata` field has been renamed to `metadataRpc`. Whether a function needs `metadataRpc` is documented for each function.
- `deriveAddress`'s 2nd argument `ss58Format` is now mandatory, and does not default to Kusama's prefix anymore.
parent 87764cd2
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment