Skip to content

Commit

Permalink
feat: rpc 0.2.0 plane implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Oct 24, 2022
1 parent e8cc71c commit 35a880c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
68 changes: 36 additions & 32 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,33 +296,40 @@ export class RpcProvider implements ProviderInterface {
details: InvocationsDetailsWithNonce
): Promise<DeclareContractResponse> {
return this.fetchEndpoint('starknet_addDeclareTransaction', {
contract_class: {
program: contractDefinition.program,
entry_points_by_type: contractDefinition.entry_points_by_type,
abi: contractDefinition.abi, // rpc 2.0
declare_transaction: {
contract_class: {
program: contractDefinition.program,
entry_points_by_type: contractDefinition.entry_points_by_type,
abi: contractDefinition.abi, // rpc 2.0
},
type: 'DECLARE',
version: toHex(toBN(details.version || 0)),
max_fee: toHex(toBN(details.maxFee || 0)),
signature: bigNumberishArrayToHexadecimalStringArray(signature || []),
sender_address: senderAddress,
nonce: toHex(toBN(details.nonce)),
},
version: toHex(toBN(details.version || 0)),
max_fee: toHex(toBN(details.maxFee || 0)),
signature: bigNumberishArrayToHexadecimalStringArray(signature || []),
sender_address: senderAddress,
nonce: toHex(toBN(details.nonce)),
});
}

public async deployContract({
contract,
constructorCalldata,
addressSalt,
details,
}: DeployContractPayload): Promise<DeployContractResponse> {
const contractDefinition = parseContract(contract);

return this.fetchEndpoint('starknet_addDeployTransaction', {
contract_address_salt: addressSalt ?? randomAddress(),
constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata ?? []),
contract_definition: {
program: contractDefinition.program,
entry_points_by_type: contractDefinition.entry_points_by_type,
abi: contractDefinition.abi, // rpc 2.0
deploy_transaction: {
contract_address_salt: addressSalt ?? randomAddress(),
constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata ?? []),
contract_class: {
program: contractDefinition.program,
entry_points_by_type: contractDefinition.entry_points_by_type,
abi: contractDefinition.abi, // rpc 2.0
},
type: 'DEPLOY',
version: toHex(toBN(details.version || 0)),
},
});
}
Expand All @@ -331,11 +338,17 @@ export class RpcProvider implements ProviderInterface {
classHash,
constructorCalldata,
addressSalt,
details,
}: DeployAccountContractPayload): 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 || []),
nonce: toHex(toBN(details.nonce)),
});
}

Expand All @@ -344,27 +357,18 @@ export class RpcProvider implements ProviderInterface {
details: InvocationsDetailsWithNonce
): Promise<InvokeFunctionResponse> {
return this.fetchEndpoint('starknet_addInvokeTransaction', {
function_invocation: {
contract_address: functionInvocation.contractAddress,
invoke_transaction: {
sender_address: functionInvocation.contractAddress,
calldata: parseCalldata(functionInvocation.calldata),
type: 'INVOKE',
max_fee: toHex(toBN(details.maxFee || 0)),
version: toHex(toBN(details.version || 0)),
signature: bigNumberishArrayToHexadecimalStringArray(functionInvocation.signature || []),
nonce: toHex(toBN(details.nonce)),
},
signature: bigNumberishArrayToHexadecimalStringArray(functionInvocation.signature || []),
max_fee: toHex(toBN(details.maxFee || 0)),
version: toHex(toBN(details.version || 0)),
});
}

/*
sender_address: ADDRESS;
calldata: Array<FELT>;
type: TXN_TYPE;
max_fee: FELT;
version: NUM_AS_HEX;
signature: SIGNATURE;
nonce: FELT;
*/

// Methods from Interface
public async callContract(
call: Call,
Expand Down
6 changes: 3 additions & 3 deletions src/types/api/openrpcv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type BLOCK_HASH = FELT;
type TXN_HASH = FELT;
type PROTOCOL_VERSION = string;
type TXN_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'INVOKE' | 'L1_HANDLER';
type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'INVOKE' | 'L1_HANDLER' | 'DEPLOY_ACCOUNT'; // DEPLOY_ACCOUNT Missing in RPC 0.2.1rc
type BLOCK_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
enum BLOCK_TAG {
'latest',
Expand Down Expand Up @@ -120,7 +120,7 @@ type DEPLOY_ACCOUNT_TXN = COMMON_TXN_PROPERTIES & DEPLOY_ACCOUNT_TXN_PROPERTIES;

type DEPLOY_ACCOUNT_TXN_PROPERTIES = {
contract_address_salt: FELT;
constructor_calldata: FELT;
constructor_calldata: Array<FELT>;
class_hash: FELT;
};

Expand Down Expand Up @@ -171,7 +171,7 @@ type DEPLOY_TXN_PROPERTIES = {
version: NUM_AS_HEX;
type: TXN_TYPE;
contract_address_salt: FELT;
constructor_calldata: FELT;
constructor_calldata: Array<FELT>;
};

type INVOKE_TXN_V0 = FUNCTION_CALL;
Expand Down

0 comments on commit 35a880c

Please sign in to comment.