Skip to content

Commit

Permalink
Add smart rollup address support
Browse files Browse the repository at this point in the history
  • Loading branch information
OKendigelyan committed Nov 1, 2024
1 parent e7b81b3 commit 71533de
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion apps/desktop/src/components/AddressPill/AddressPill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const AddressPill = memo(
showIcons,
addressKind,
addressAlias,
address,
onClick,
elementRef,
isMouseHover,
Expand Down Expand Up @@ -109,7 +110,7 @@ export const AddressPill = memo(
</PopoverBody>
</PopoverContent>
</Popover>
{showIcons && (
{showIcons && address.type !== "smart_rollup" && (
<RightIcon
marginRight="4px"
stroke={colors.gray[300]}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/Operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export const toLambda = (operation: Operation): MichelsonV1Expression[] => {
operation.recipient.pkh,
Number(operation.amount)
);
default:
throw new Error(`${operation.recipient.type} is not supported yet`);
}
// eslint-disable-next-line no-fallthrough
case "fa1.2":
Expand Down
19 changes: 18 additions & 1 deletion packages/tezos/src/Address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ValidationResult, validateAddress } from "@taquito/utils";

import { type Address, type ContractAddress, type ImplicitAddress } from "./types";
import {
type Address,
type ContractAddress,
type ImplicitAddress,
type SmartRollupAddress,
} from "./types";

export const parsePkh = (pkh: string): Address => {
if (isValidContractPkh(pkh)) {
Expand All @@ -9,6 +14,9 @@ export const parsePkh = (pkh: string): Address => {
if (isValidImplicitPkh(pkh)) {
return parseImplicitPkh(pkh);
}
if (isValidSmartRollupPkh(pkh)) {
return parseSmartRollupPkh(pkh);
}
throw new Error(`Cannot parse address type: ${pkh}`);
};

Expand All @@ -18,6 +26,8 @@ export const isValidContractPkh = (pkh: string) => isAddressValid(pkh) && pkh.ma

export const isValidImplicitPkh = (pkh: string) => isAddressValid(pkh) && pkh.match(/^tz[1234]\w+/);

export const isValidSmartRollupPkh = (pkh: string) => isAddressValid(pkh) && pkh.match(/^sr1\w+/);

export const parseContractPkh = (pkh: string): ContractAddress => {
if (isValidContractPkh(pkh)) {
return { type: "contract", pkh };
Expand All @@ -31,3 +41,10 @@ export const parseImplicitPkh = (pkh: string): ImplicitAddress => {
}
throw new Error(`Invalid implicit address: ${pkh}`);
};

export const parseSmartRollupPkh = (pkh: string): SmartRollupAddress => {
if (isValidSmartRollupPkh(pkh)) {
return { type: "smart_rollup", pkh };
}
throw new Error(`Invalid smart rollup address: ${pkh}`);
};
7 changes: 6 additions & 1 deletion packages/tezos/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export type ImplicitAddress = {
pkh: RawPkh;
};

export type Address = ContractAddress | ImplicitAddress;
export type SmartRollupAddress = {
type: "smart_rollup";
pkh: RawPkh;
};

export type Address = ContractAddress | ImplicitAddress | SmartRollupAddress;

export type Estimation = {
storageLimit: number;
Expand Down

0 comments on commit 71533de

Please sign in to comment.