Skip to content

Commit

Permalink
chore: define isSierra resulting type
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Jun 23, 2023
1 parent 2ba0f7d commit 343a711
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 7 additions & 9 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,13 @@ export class RpcProvider implements ProviderInterface {
details: InvocationsDetailsWithNonce
): Promise<DeclareContractResponse> {
if (!isSierra(contract)) {
const legacyContract = contract as LegacyContractClass;
return this.fetchEndpoint('starknet_addDeclareTransaction', {
declare_transaction: {
type: RPC.TransactionType.DECLARE,
contract_class: {
program: legacyContract.program,
entry_points_by_type: legacyContract.entry_points_by_type,
abi: legacyContract.abi,
program: contract.program,
entry_points_by_type: contract.entry_points_by_type,
abi: contract.abi,
},
version: toHex(transactionVersion),
max_fee: toHex(details.maxFee || 0),
Expand All @@ -354,15 +353,14 @@ export class RpcProvider implements ProviderInterface {
},
});
}
const sierraContract = contract as SierraContractClass;
return this.fetchEndpoint('starknet_addDeclareTransaction', {
declare_transaction: {
type: RPC.TransactionType.DECLARE,
contract_class: {
sierra_program: decompressProgram(sierraContract.sierra_program),
contract_class_version: sierraContract.contract_class_version,
entry_points_by_type: sierraContract.entry_points_by_type,
abi: sierraContract.abi,
sierra_program: decompressProgram(contract.sierra_program),
contract_class_version: contract.contract_class_version,
entry_points_by_type: contract.entry_points_by_type,
abi: contract.abi,
},
compiled_class_hash: compiledClassHash || '',
version: toHex(transactionVersion_2),
Expand Down
6 changes: 4 additions & 2 deletions src/utils/contract.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { CairoContract } from '../types/lib/contract/index';
import { CairoContract, CompiledSierra, SierraContractClass } from '../types/lib/contract/index';
import { CompleteDeclareContractPayload, DeclareContractPayload } from '../types/lib/index';
import { computeCompiledClassHash, computeContractClassHash } from './hash';
import { parse } from './json';

export function isSierra(contract: CairoContract | string) {
export function isSierra(
contract: CairoContract | string
): contract is SierraContractClass | CompiledSierra {
const compiledContract = typeof contract === 'string' ? parse(contract) : contract;
return 'sierra_program' in compiledContract;
}
Expand Down

0 comments on commit 343a711

Please sign in to comment.