forked from TonDevWallet/TonDevWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
304 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Cell } from '@ton/core' | ||
|
||
export const WalletV5R1CodeBoc = | ||
'b5ee9c720101010100230008420220834b7b72b112147e1b2fb457b84e74d1a30f04f737d4f62a668e9552d2b72f' | ||
// 'b5ee9c7201010101002300084202e4cf3b2f4c6d6a61ea0f2b5447d266785b26af3637db2deee6bcd1aa826f3412' beta | ||
|
||
export const WalletV5R1CodeCell = Cell.fromBoc(Buffer.from(WalletV5R1CodeBoc, 'hex'))[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* eslint-disable no-useless-constructor */ | ||
import { Address, beginCell, Cell, MessageRelaxed, SendMode, storeMessageRelaxed } from '@ton/core' | ||
|
||
export class ActionSendMsg { | ||
public static readonly tag = 0x0ec3c86d | ||
|
||
public readonly tag = ActionSendMsg.tag | ||
|
||
constructor( | ||
public readonly mode: SendMode, | ||
public readonly outMsg: MessageRelaxed | ||
) {} | ||
|
||
public serialize(): Cell { | ||
return beginCell() | ||
.storeUint(this.tag, 32) | ||
.storeUint(this.mode | SendMode.IGNORE_ERRORS, 8) | ||
.storeRef(beginCell().store(storeMessageRelaxed(this.outMsg)).endCell()) | ||
.endCell() | ||
} | ||
} | ||
|
||
export class ActionAddExtension { | ||
public static readonly tag = 0x02 | ||
|
||
public readonly tag = ActionAddExtension.tag | ||
|
||
constructor(public readonly address: Address) {} | ||
|
||
public serialize(): Cell { | ||
return beginCell().storeUint(this.tag, 8).storeAddress(this.address).endCell() | ||
} | ||
} | ||
|
||
export class ActionRemoveExtension { | ||
public static readonly tag = 0x03 | ||
|
||
public readonly tag = ActionRemoveExtension.tag | ||
|
||
constructor(public readonly address: Address) {} | ||
|
||
public serialize(): Cell { | ||
return beginCell().storeUint(this.tag, 8).storeAddress(this.address).endCell() | ||
} | ||
} | ||
|
||
export class ActionSetSignatureAuthAllowed { | ||
public static readonly tag = 0x04 | ||
|
||
public readonly tag = ActionSetSignatureAuthAllowed.tag | ||
|
||
constructor(public readonly allowed: boolean) {} | ||
|
||
public serialize(): Cell { | ||
return beginCell() | ||
.storeUint(this.tag, 8) | ||
.storeUint(this.allowed ? 1 : 0, 1) | ||
.endCell() | ||
} | ||
} | ||
|
||
export type OutAction = ActionSendMsg | ||
export type ExtendedAction = | ||
| ActionAddExtension | ||
| ActionRemoveExtension | ||
| ActionSetSignatureAuthAllowed | ||
|
||
export function isExtendedAction(action: OutAction | ExtendedAction): action is ExtendedAction { | ||
return ( | ||
action.tag === ActionAddExtension.tag || | ||
action.tag === ActionRemoveExtension.tag || | ||
action.tag === ActionSetSignatureAuthAllowed.tag | ||
) | ||
} | ||
|
||
function packActionsListOut(actions: (OutAction | ExtendedAction)[]): Cell { | ||
if (actions.length === 0) { | ||
return beginCell().endCell() | ||
} | ||
|
||
const [action, ...rest] = actions | ||
|
||
if (isExtendedAction(action)) { | ||
throw new Error('Actions bust be in an order: all extended actions, all out actions') | ||
} | ||
|
||
return beginCell() | ||
.storeRef(packActionsListOut(rest)) | ||
.storeSlice(action.serialize().beginParse()) | ||
.endCell() | ||
} | ||
|
||
function packExtendedActions(extendedActions: ExtendedAction[]): Cell { | ||
const first = extendedActions[0] | ||
const rest = extendedActions.slice(1) | ||
let builder = beginCell().storeSlice(first.serialize().beginParse()) | ||
if (rest.length > 0) { | ||
builder = builder.storeRef(packExtendedActions(extendedActions.slice(1))) | ||
} | ||
return builder.endCell() | ||
} | ||
|
||
function packActionsListExtended(actions: (OutAction | ExtendedAction)[]): Cell { | ||
const extendedActions: ExtendedAction[] = [] | ||
const outActions: OutAction[] = [] | ||
actions.forEach((action) => { | ||
if (isExtendedAction(action)) { | ||
extendedActions.push(action) | ||
} else { | ||
outActions.push(action) | ||
} | ||
}) | ||
|
||
let builder = beginCell() | ||
if (outActions.length === 0) { | ||
builder = builder.storeUint(0, 1) | ||
} else { | ||
builder = builder.storeMaybeRef(packActionsListOut(outActions.slice().reverse())) | ||
} | ||
if (extendedActions.length === 0) { | ||
builder = builder.storeUint(0, 1) | ||
} else { | ||
const first = extendedActions[0] | ||
const rest = extendedActions.slice(1) | ||
builder = builder.storeUint(1, 1).storeSlice(first.serialize().beginParse()) | ||
if (rest.length > 0) { | ||
builder = builder.storeRef(packExtendedActions(rest)) | ||
} | ||
} | ||
return builder.endCell() | ||
} | ||
|
||
export function packActionsList(actions: (OutAction | ExtendedAction)[]): Cell { | ||
return packActionsListExtended(actions) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.