Skip to content

Commit 3b2914a

Browse files
committed
refactor(cleanup): rpc 0.6, accountInvocationsFactory cleanup
1 parent 89f8221 commit 3b2914a

File tree

4 files changed

+46
-35
lines changed

4 files changed

+46
-35
lines changed

src/account/default.ts

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Provider, ProviderInterface } from '../provider';
33
import { Signer, SignerInterface } from '../signer';
44
import {
55
Abi,
6-
AccountInvocationItem,
76
AccountInvocations,
87
AccountInvocationsFactoryDetails,
98
AllowArray,
@@ -54,6 +53,7 @@ import {
5453
formatSignature,
5554
randomAddress,
5655
reduceV2,
56+
toETransactionVersions,
5757
toFeeVersion,
5858
toTransactionVersion,
5959
v3Details,
@@ -805,10 +805,10 @@ export class Account extends Provider implements AccountInterface {
805805
invocations: Invocations,
806806
details: AccountInvocationsFactoryDetails
807807
) {
808-
const { versions, nonce, blockIdentifier } = details;
809-
// const version = versions[1]; // TODO: ovdje je bilo 0 prije a tribalo bi bit 1 LOL
808+
const { nonce, blockIdentifier } = details;
810809
const safeNonce = await this.getNonceSafe(nonce);
811810
const chainId = await this.getChainId();
811+
const versions = details.versions.map((it) => toETransactionVersions(it));
812812

813813
// BULK ACTION FROM NEW ACCOUNT START WITH DEPLOY_ACCOUNT
814814
const tx0Payload: any = 'payload' in invocations[0] ? invocations[0].payload : invocations[0];
@@ -820,72 +820,74 @@ export class Account extends Provider implements AccountInterface {
820820
return Promise.all(
821821
([] as Invocations).concat(invocations).map(async (transaction, index: number) => {
822822
const txPayload: any = 'payload' in transaction ? transaction.payload : transaction;
823-
const signerDetails: InvocationsSignerDetails = {
823+
const signerDetails = {
824824
...v3Details(details),
825825
walletAddress: this.address,
826826
nonce: toBigInt(Number(safeNonce) + index),
827827
maxFee: ZERO,
828-
version: versions[1],
829828
chainId,
830829
cairoVersion,
830+
version: '' as ETransactionVersion,
831831
};
832832
const common = {
833833
type: transaction.type,
834-
version: versions[1],
835834
nonce: toBigInt(Number(safeNonce) + index),
836835
blockIdentifier,
836+
version: '' as ETransactionVersion,
837837
};
838838

839839
if (transaction.type === TransactionType.INVOKE) {
840-
// todo: moze bit 1 ili 3
841-
const versionX = reduceV2(versions[1] as ETransactionVersion);
840+
// 1 or 3
841+
const versionX = reduceV2(versions[1]);
842+
signerDetails.version = versionX;
843+
common.version = versionX;
844+
842845
const payload = await this.buildInvocation(
843846
([] as Call[]).concat(txPayload),
844-
{
845-
...signerDetails,
846-
version: versionX,
847-
} as InvocationsSignerDetails // TODO: Fix force
847+
signerDetails
848848
);
849849
return {
850-
...{ ...common, version: versionX },
850+
...common,
851851
...payload,
852-
} as AccountInvocationItem;
852+
};
853853
}
854854
if (transaction.type === TransactionType.DEPLOY) {
855-
// todo: moze bit 1 ili 3
856-
const versionX = reduceV2(versions[1] as ETransactionVersion);
855+
// 1 or 3
856+
const versionX = reduceV2(versions[1]);
857+
signerDetails.version = versionX;
858+
common.version = versionX;
859+
857860
const calls = this.buildUDCContractPayload(txPayload);
858-
const payload = await this.buildInvocation(calls, {
859-
...signerDetails,
860-
version: versionX,
861-
} as InvocationsSignerDetails); // TODO: Fix force
861+
const payload = await this.buildInvocation(calls, signerDetails);
862862
return {
863-
...{ ...common, version: versionX },
863+
...common,
864864
...payload,
865865
type: TransactionType.INVOKE,
866-
} as AccountInvocationItem;
866+
};
867867
}
868868
if (transaction.type === TransactionType.DECLARE) {
869-
// todo: moze bit 1 ili 2,3 OK
870-
signerDetails.version = !isSierra(txPayload.contract) ? versions[0] : versions[1];
869+
// 1 (Cairo0) or 2 or 3
870+
const versionX = !isSierra(txPayload.contract) ? versions[0] : versions[1];
871+
signerDetails.version = versionX;
872+
common.version = versionX;
873+
871874
const payload = await this.buildDeclarePayload(txPayload, signerDetails);
872875
return {
873876
...common,
874877
...payload,
875-
version: signerDetails.version,
876-
} as AccountInvocationItem;
878+
};
877879
}
878880
if (transaction.type === TransactionType.DEPLOY_ACCOUNT) {
879-
// todo: moze bit 1 ili 3
880-
const versionX = reduceV2(versions[1] as ETransactionVersion);
881-
const payload = await this.buildAccountDeployPayload(txPayload, {
882-
...signerDetails,
883-
version: versionX,
884-
} as InvocationsSignerDetails); // TODO: Fix force
881+
// 1 or 3
882+
const versionX = reduceV2(versions[1]);
883+
signerDetails.version = versionX;
884+
common.version = versionX;
885+
886+
const payload = await this.buildAccountDeployPayload(txPayload, signerDetails);
885887
return {
886-
...{ ...common, version: versionX },
888+
...common,
887889
...payload,
888-
} as AccountInvocationItem;
890+
};
889891
}
890892
throw Error(`accountInvocationsFactory: unsupported transaction type: ${transaction}`);
891893
})

src/types/api/rpcspec_0_6/errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export interface INSUFFICIENT_ACCOUNT_BALANCE {
111111
export interface VALIDATION_FAILURE {
112112
code: 55;
113113
message: 'Account validation failed';
114+
data: string;
114115
}
115116

116117
export interface COMPILATION_FAILED {

src/types/api/rpcspec_0_6/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* version 0.6.0-rc2
2+
* version 0.6.0
33
*/
44

55
export { Methods } from './methods';

src/utils/stark.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,11 @@ export function reduceV2(providedVersion: ETransactionVersion) {
187187
if (providedVersion === ETransactionVersion.V2) return ETransactionVersion.V1;
188188
return providedVersion;
189189
}
190+
191+
export function toETransactionVersions(version: string) {
192+
if (!Object.values(ETransactionVersion).includes(version as any)) {
193+
throw Error(`Provided ${version} is not ETransactionVersion`);
194+
}
195+
196+
return version as ETransactionVersion;
197+
}

0 commit comments

Comments
 (0)