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

Extracurrency support #63

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/contract/ContractProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Sender } from './Sender';
import { Contract } from './Contract';
import { Address } from "../address/Address";
import { Transaction } from "../types/Transaction";
import { Dictionary } from "../dict/Dictionary";
import { OpenedContract } from "./openContract";

export type ContractGetMethodResult = {
Expand All @@ -28,7 +29,7 @@ export interface ContractProvider {
getState(): Promise<ContractState>;
get(name: string | number, args: TupleItem[]): Promise<ContractGetMethodResult>;
external(message: Cell): Promise<void>;
internal(via: Sender, args: { value: bigint | string, bounce?: Maybe<boolean>, sendMode?: SendMode, body?: Maybe<Cell | string> }): Promise<void>;
internal(via: Sender, args: { value: bigint | string, ec?: [number, bigint][], bounce?: Maybe<boolean>, sendMode?: SendMode, body?: Maybe<Cell | string> }): Promise<void>;
open<T extends Contract>(contract: T): OpenedContract<T>;
getTransactions(address: Address, lt: bigint, hash: Buffer, limit?: number): Promise<Transaction[]>;
}
5 changes: 5 additions & 0 deletions src/contract/ContractState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@

import { Maybe } from "../utils/maybe";

type ExtraCurrencyMap = {
[k: number]: bigint
}

export type ContractState = {
balance: bigint,
ec: Maybe<ExtraCurrencyMap>,
last: { lt: bigint, hash: Buffer } | null,
state: { type: 'uninit' } | { type: 'active', code: Maybe<Buffer>, data: Maybe<Buffer> } | { type: 'frozen', stateHash: Buffer }
};
1 change: 1 addition & 0 deletions src/contract/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Maybe } from "../utils/maybe";
export type SenderArguments = {
value: bigint,
to: Address,
ec?: Maybe<[number, bigint][]>,
sendMode?: Maybe<SendMode>,
bounce?: Maybe<boolean>,
init?: Maybe<StateInit>,
Expand Down
14 changes: 13 additions & 1 deletion src/types/_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import { beginCell } from "../boc/Builder";
import { toNano } from "../utils/convert";
import { MessageRelaxed } from "./MessageRelaxed";
import { Message } from "./Message";
import { Dictionary } from "../dict/Dictionary";
import { StateInit } from "./StateInit";

export function internal(src: {
to: Address | string,
value: bigint | string,
ec?: Maybe<[number, bigint][]>,
bounce?: Maybe<boolean>,
init?: Maybe<StateInit>,
body?: Maybe<Cell | string>
Expand Down Expand Up @@ -47,6 +49,16 @@ export function internal(src: {
value = src.value;
}

let other: Dictionary<number, bigint> | undefined;
if(src.ec) {
// Resolve value
other = Dictionary.empty(Dictionary.Keys.Uint(32), Dictionary.Values.BigVarUint(5));
for(let tuple of src.ec) {
other.set(tuple[0], tuple[1]);
}
}


// Resolve body
let body: Cell = Cell.EMPTY;
if (typeof src.body === 'string') {
Expand All @@ -60,7 +72,7 @@ export function internal(src: {
info: {
type: 'internal',
dest: to,
value: { coins: value },
value: { coins: value, other },
bounce,
ihrDisabled: true,
bounced: false,
Expand Down
Loading