Skip to content

Commit

Permalink
feat: rpc0.2.1 definition migration comlete
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Nov 11, 2022
1 parent 72178df commit 35c5a06
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 736 deletions.
13 changes: 10 additions & 3 deletions src/provider/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import {
InvocationsDetailsWithNonce,
InvokeFunctionResponse,
} from '../types';
import { DeclareContractTransaction, DeployAccountContractTransaction } from '../types/lib';
import {
DeclareContractTransaction,
DeployAccountContractTransaction,
InvocationsDetails,
} from '../types/lib';
import { BigNumberish } from '../utils/number';
import { ProviderInterface } from './interface';
import { RpcProvider, RpcProviderOptions } from './rpc';
Expand Down Expand Up @@ -118,8 +122,11 @@ export class Provider implements ProviderInterface {
return this.provider.invokeFunction(functionInvocation, details);
}

public async deployContract(payload: DeployContractPayload): Promise<DeployContractResponse> {
return this.provider.deployContract(payload);
public async deployContract(
payload: DeployContractPayload,
details: InvocationsDetails
): Promise<DeployContractResponse> {
return this.provider.deployContract(payload, details);
}

public async deployAccountContract(
Expand Down
6 changes: 5 additions & 1 deletion src/provider/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
DeclareContractTransaction,
DeployAccountContractPayload,
DeployAccountContractTransaction,
InvocationsDetails,
} from '../types/lib';
import type { BigNumberish } from '../utils/number';
import { BlockIdentifier } from './utils';
Expand Down Expand Up @@ -125,7 +126,10 @@ export abstract class ProviderInterface {
* - address salt
* @returns a confirmation of sending a transaction on the starknet contract
*/
public abstract deployContract(payload: DeployContractPayload): Promise<DeployContractResponse>;
public abstract deployContract(
payload: DeployContractPayload,
details?: InvocationsDetails
): Promise<DeployContractResponse>;

/**
* Deploys a given compiled Account contract (json) to starknet
Expand Down
26 changes: 11 additions & 15 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
import { RPC } from '../types/api';
import {
DeclareContractTransaction,
DeployAccountContractPayload,
DeployAccountContractTransaction,
InvocationsDetails,
} from '../types/lib';
import fetch from '../utils/fetchPonyfill';
import { getSelectorFromName } from '../utils/hash';
Expand Down Expand Up @@ -316,12 +316,10 @@ export class RpcProvider implements ProviderInterface {
});
}

public async deployContract({
contract,
constructorCalldata,
addressSalt,
details,
}: DeployContractPayload): Promise<DeployContractResponse> {
public async deployContract(
{ contract, constructorCalldata, addressSalt }: DeployContractPayload,
details: InvocationsDetails
): Promise<DeployContractResponse> {
const contractDefinition = parseContract(contract);
return this.fetchEndpoint('starknet_addDeployTransaction', {
deploy_transaction: {
Expand All @@ -330,28 +328,26 @@ export class RpcProvider implements ProviderInterface {
contract_class: {
program: contractDefinition.program,
entry_points_by_type: contractDefinition.entry_points_by_type,
abi: contractDefinition.abi, // rpc 2.0
abi: contractDefinition.abi,
},
type: 'DEPLOY',
version: toHex(toBN(details.version || 0)),
},
});
}

public async deployAccountContract({
classHash,
constructorCalldata,
addressSalt,
details,
}: DeployAccountContractPayload): Promise<DeployContractResponse> {
public async deployAccountContract(
{ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction,
details: InvocationsDetailsWithNonce
): Promise<DeployContractResponse> {
return this.fetchEndpoint('starknet_addDeployAccountTransaction', {
constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata || []),
class_hash: toHex(toBN(classHash)),
contract_address_salt: toHex(toBN(addressSalt || 0)),
type: 'DEPLOY',
max_fee: toHex(toBN(details.maxFee || 0)),
version: toHex(toBN(details.version || 0)),
signature: bigNumberishArrayToHexadecimalStringArray(details.signature || []),
signature: bigNumberishArrayToHexadecimalStringArray(signature || []),
nonce: toHex(toBN(details.nonce)),
});
}
Expand Down
Loading

0 comments on commit 35c5a06

Please sign in to comment.