Skip to content

Commit

Permalink
fix coins, add booltrue and boolfalse
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Nov 11, 2024
1 parent 62e9d3f commit 57e7add
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 120 deletions.
6 changes: 6 additions & 0 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,14 @@ export type TLBExoticType = {
kind: "TLBExoticType";
};

export type TLBBoolType = {
kind: "TLBBoolType";
value: boolean | undefined;
}

export type TLBFieldType =
| TLBNumberType
| TLBBoolType
| TLBBitsType
| TLBNamedType
| TLBCoinsType
Expand Down
3 changes: 2 additions & 1 deletion src/astbuilder/fill_constructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ function checkAndRemovePrimitives(
typesToDelete.set("VarInteger", ["d466ed5"])
typesToDelete.set("HashmapE", ["32bae5cb", "28fa3979"])
typesToDelete.set("HashmapAugE", ["36820dce", "5f71ac75"])
typesToDelete.set("Coins", ["258097e8"])
typesToDelete.set("BoolTrue", ["943ebb5"])
typesToDelete.set("BoolFalse", ["1f5e497d"])

typesToDelete.forEach((opCodesExpected: string[], typeName: string) => {
let typeItems = typeDeclarations.get(typeName);
Expand Down
8 changes: 7 additions & 1 deletion src/astbuilder/handle_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,14 @@ export function getType(
return { kind: "TLBAddressType", addrType: "Any" };
} else if (expr.name == "Bit") {
return { kind: "TLBBitsType", bits: new TLBNumberExpr(1) };
} else if (expr.name == "Grams") {
} else if (expr.name == "Grams" || expr.name == "Coins") {
return { kind: "TLBCoinsType" };
} else if (expr.name == "Bool") {
return { kind: "TLBBoolType", value: undefined };
} else if (expr.name == "BoolFalse") {
return { kind: "TLBBoolType", value: false };
} else if (expr.name == "BoolTrue") {
return { kind: "TLBBoolType", value: true };
} else {
if (constructor.variablesMap.get(expr.name)?.type == "#") {
return {
Expand Down
39 changes: 25 additions & 14 deletions src/generators/typescript/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,25 +284,30 @@ export function storeBool(bool: Bool): (builder: Builder) => void {
}
export interface Coins {
readonly kind: 'Coins';
readonly grams: bigint;
}
export function loadCoins(slice: Slice): Coins {
let grams: bigint = slice.loadCoins();
return {
kind: 'Coins',
grams: grams,
}
export function loadBoolFalse(slice: Slice): Bool {
if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b0))) {
slice.loadUint(1);
return {
kind: 'Bool',
value: false
}
}
throw new Error('Expected one of "BoolFalse" in loading "BoolFalse", but data does not satisfy any constructor');
}
export function storeCoins(coins: Coins): (builder: Builder) => void {
return ((builder: Builder) => {
builder.storeCoins(coins.grams);
})
export function loadBoolTrue(slice: Slice): Bool {
if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b1))) {
slice.loadUint(1);
return {
kind: 'Bool',
value: true
}
}
throw new Error('Expected one of "BoolTrue" in loading "BoolTrue", but data does not satisfy any constructor');
}
`))
}
Expand Down Expand Up @@ -986,6 +991,12 @@ export function storeCoins(coins: Coins): (builder: Builder) => void {
if (subExprInfo.storeStmtInside) {
result.storeStmtInside = storeInNewCell(currentCell, subExprInfo.storeStmtInside);
}
} else if (fieldType.kind == "TLBBoolType") {
let loadFunction = 'load' + (fieldType.value === undefined ? 'Bool': (fieldType.value ? 'BoolTrue': 'BoolFalse'));
result.loadExpr = tFunctionCall(id(loadFunction), [id("slice")]);
result.typeParamExpr = id('Bool');
result.storeStmtInside = tExpressionStatement(tFunctionCall(tFunctionCall(id('storeBool'), storeParametersInside), [id('builder')]));
result.storeStmtOutside = tExpressionStatement(tFunctionCall(tFunctionCall(id('storeBool'), storeParametersOutside), [id('builder')]));
} else if (fieldType.kind == "TLBHashmapType") {
let keyForLoad: Expression = dictKeyExpr(fieldType.key, ctx);
let keyForStore: Expression = dictKeyExpr(fieldType.key, ctx, ctx.typeName);
Expand Down
156 changes: 67 additions & 89 deletions test/generated_files/generated_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,30 @@ export function storeBool(bool: Bool): (builder: Builder) => void {

}

export interface Coins {
readonly kind: 'Coins';
readonly grams: bigint;
}

export function loadCoins(slice: Slice): Coins {
let grams: bigint = slice.loadCoins();
return {
kind: 'Coins',
grams: grams,
}

export function loadBoolFalse(slice: Slice): Bool {
if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b0))) {
slice.loadUint(1);
return {
kind: 'Bool',
value: false
}

}
throw new Error('Expected one of "BoolFalse" in loading "BoolFalse", but data does not satisfy any constructor');
}

export function storeCoins(coins: Coins): (builder: Builder) => void {
return ((builder: Builder) => {
builder.storeCoins(coins.grams);
})
export function loadBoolTrue(slice: Slice): Bool {
if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b1))) {
slice.loadUint(1);
return {
kind: 'Bool',
value: true
}

}
throw new Error('Expected one of "BoolTrue" in loading "BoolTrue", but data does not satisfy any constructor');
}

export function copyCellToBuilder(from: Cell, to: Builder): void {
Expand All @@ -78,18 +83,6 @@ export interface True {
readonly kind: 'True';
}

// bool_false$0 = BoolFalse;

export interface BoolFalse {
readonly kind: 'BoolFalse';
}

// bool_true$1 = BoolTrue;

export interface BoolTrue {
readonly kind: 'BoolTrue';
}

// nothing$0 {X:Type} = Maybe X;

// just$1 {X:Type} value:X = Maybe X;
Expand Down Expand Up @@ -396,6 +389,13 @@ export interface Anycast {
readonly rewrite_pfx: BitString;
}

// _ grams:Grams = Coins;

export interface Coins {
readonly kind: 'Coins';
readonly grams: bigint;
}

/*
extra_currencies$_ dict:(HashmapE 32 (VarUInteger 32))
= ExtraCurrencyCollection;
Expand Down Expand Up @@ -3082,12 +3082,12 @@ jetton_bridge_prices#_ bridge_burn_fee:Coins bridge_mint_fee:Coins

export interface JettonBridgePrices {
readonly kind: 'JettonBridgePrices';
readonly bridge_burn_fee: Coins;
readonly bridge_mint_fee: Coins;
readonly wallet_min_tons_for_storage: Coins;
readonly wallet_gas_consumption: Coins;
readonly minter_min_tons_for_storage: Coins;
readonly discover_gas_consumption: Coins;
readonly bridge_burn_fee: bigint;
readonly bridge_mint_fee: bigint;
readonly wallet_min_tons_for_storage: bigint;
readonly wallet_gas_consumption: bigint;
readonly minter_min_tons_for_storage: bigint;
readonly discover_gas_consumption: bigint;
}

// jetton_bridge_params_v0#00 bridge_address:bits256 oracles_address:bits256 oracles:(HashmapE 256 uint256) state_flags:uint8 burn_bridge_fee:Coins = JettonBridgeParams;
Expand All @@ -3102,7 +3102,7 @@ export interface JettonBridgeParams_jetton_bridge_params_v0 {
readonly oracles_address: Buffer;
readonly oracles: Dictionary<bigint, bigint>;
readonly state_flags: number;
readonly burn_bridge_fee: Coins;
readonly burn_bridge_fee: bigint;
}

export interface JettonBridgeParams_jetton_bridge_params_v1 {
Expand Down Expand Up @@ -3825,46 +3825,6 @@ export function storeTrue(true0: True): (builder: Builder) => void {

}

// bool_false$0 = BoolFalse;

export function loadBoolFalse(slice: Slice): BoolFalse {
if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b0))) {
slice.loadUint(1);
return {
kind: 'BoolFalse',
}

}
throw new Error('Expected one of "BoolFalse" in loading "BoolFalse", but data does not satisfy any constructor');
}

export function storeBoolFalse(boolFalse: BoolFalse): (builder: Builder) => void {
return ((builder: Builder) => {
builder.storeUint(0b0, 1);
})

}

// bool_true$1 = BoolTrue;

export function loadBoolTrue(slice: Slice): BoolTrue {
if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b1))) {
slice.loadUint(1);
return {
kind: 'BoolTrue',
}

}
throw new Error('Expected one of "BoolTrue" in loading "BoolTrue", but data does not satisfy any constructor');
}

export function storeBoolTrue(boolTrue: BoolTrue): (builder: Builder) => void {
return ((builder: Builder) => {
builder.storeUint(0b1, 1);
})

}

// nothing$0 {X:Type} = Maybe X;

// just$1 {X:Type} value:X = Maybe X;
Expand Down Expand Up @@ -4741,6 +4701,24 @@ export function storeAnycast(anycast: Anycast): (builder: Builder) => void {

}

// _ grams:Grams = Coins;

export function loadCoins(slice: Slice): Coins {
let grams: bigint = slice.loadCoins();
return {
kind: 'Coins',
grams: grams,
}

}

export function storeCoins(coins: Coins): (builder: Builder) => void {
return ((builder: Builder) => {
builder.storeCoins(coins.grams);
})

}

/*
extra_currencies$_ dict:(HashmapE 32 (VarUInteger 32))
= ExtraCurrencyCollection;
Expand Down Expand Up @@ -9663,7 +9641,7 @@ export function loadMcStateExtra(slice: Slice): McStateExtra {
let flags: number = slice1.loadUint(16);
let validator_info: ValidatorInfo = loadValidatorInfo(slice1);
let prev_blocks: OldMcBlocksInfo = loadOldMcBlocksInfo(slice1);
let after_key_block: Bool = loadBool(slice1);
let after_key_block: Bool = loadBool(slice);
let last_key_block: Maybe<ExtBlkRef> = loadMaybe<ExtBlkRef>(slice1, loadExtBlkRef);
let block_create_stats: BlockCreateStats | undefined = ((flags & (1 << 0)) ? loadBlockCreateStats(slice1) : undefined);
let global_balance: CurrencyCollection = loadCurrencyCollection(slice);
Expand Down Expand Up @@ -9693,7 +9671,7 @@ export function storeMcStateExtra(mcStateExtra: McStateExtra): (builder: Builder
cell1.storeUint(mcStateExtra.flags, 16);
storeValidatorInfo(mcStateExtra.validator_info)(cell1);
storeOldMcBlocksInfo(mcStateExtra.prev_blocks)(cell1);
storeBool(mcStateExtra.after_key_block)(cell1);
storeBool(mcStateExtra.after_key_block)(builder);
storeMaybe<ExtBlkRef>(mcStateExtra.last_key_block, storeExtBlkRef)(cell1);
if ((mcStateExtra.block_create_stats != undefined)) {
storeBlockCreateStats(mcStateExtra.block_create_stats)(cell1);
Expand Down Expand Up @@ -12504,12 +12482,12 @@ jetton_bridge_prices#_ bridge_burn_fee:Coins bridge_mint_fee:Coins
*/

export function loadJettonBridgePrices(slice: Slice): JettonBridgePrices {
let bridge_burn_fee: Coins = loadCoins(slice);
let bridge_mint_fee: Coins = loadCoins(slice);
let wallet_min_tons_for_storage: Coins = loadCoins(slice);
let wallet_gas_consumption: Coins = loadCoins(slice);
let minter_min_tons_for_storage: Coins = loadCoins(slice);
let discover_gas_consumption: Coins = loadCoins(slice);
let bridge_burn_fee: bigint = slice.loadCoins();
let bridge_mint_fee: bigint = slice.loadCoins();
let wallet_min_tons_for_storage: bigint = slice.loadCoins();
let wallet_gas_consumption: bigint = slice.loadCoins();
let minter_min_tons_for_storage: bigint = slice.loadCoins();
let discover_gas_consumption: bigint = slice.loadCoins();
return {
kind: 'JettonBridgePrices',
bridge_burn_fee: bridge_burn_fee,
Expand All @@ -12524,12 +12502,12 @@ export function loadJettonBridgePrices(slice: Slice): JettonBridgePrices {

export function storeJettonBridgePrices(jettonBridgePrices: JettonBridgePrices): (builder: Builder) => void {
return ((builder: Builder) => {
storeCoins(jettonBridgePrices.bridge_burn_fee)(builder);
storeCoins(jettonBridgePrices.bridge_mint_fee)(builder);
storeCoins(jettonBridgePrices.wallet_min_tons_for_storage)(builder);
storeCoins(jettonBridgePrices.wallet_gas_consumption)(builder);
storeCoins(jettonBridgePrices.minter_min_tons_for_storage)(builder);
storeCoins(jettonBridgePrices.discover_gas_consumption)(builder);
builder.storeCoins(jettonBridgePrices.bridge_burn_fee);
builder.storeCoins(jettonBridgePrices.bridge_mint_fee);
builder.storeCoins(jettonBridgePrices.wallet_min_tons_for_storage);
builder.storeCoins(jettonBridgePrices.wallet_gas_consumption);
builder.storeCoins(jettonBridgePrices.minter_min_tons_for_storage);
builder.storeCoins(jettonBridgePrices.discover_gas_consumption);
})

}
Expand All @@ -12551,7 +12529,7 @@ export function loadJettonBridgeParams(slice: Slice): JettonBridgeParams {
}),
}, slice);
let state_flags: number = slice.loadUint(8);
let burn_bridge_fee: Coins = loadCoins(slice);
let burn_bridge_fee: bigint = slice.loadCoins();
return {
kind: 'JettonBridgeParams_jetton_bridge_params_v0',
bridge_address: bridge_address,
Expand Down Expand Up @@ -12609,7 +12587,7 @@ export function storeJettonBridgeParams(jettonBridgeParams: JettonBridgeParams):
parse: () => { throw new Error('Not implemented') },
});
builder.storeUint(jettonBridgeParams.state_flags, 8);
storeCoins(jettonBridgeParams.burn_bridge_fee)(builder);
builder.storeCoins(jettonBridgeParams.burn_bridge_fee);
})

}
Expand Down
Loading

0 comments on commit 57e7add

Please sign in to comment.