Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #5

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
"build": "tsc",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint",
"version": "npm run format && git add -A src",
"prepublishOnly": "npm test ",
"version": "git add -A src",
"postversion": "git push && git push --tags",
"test:e2e": "jest --config jest.config.e2e.js",
"test:watch": "jest --watch"
Expand Down
2 changes: 0 additions & 2 deletions src/lacchain-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import {

import { LacchainTransaction } from './lacchain-transaction';


export class LacchainProvider extends JsonRpcProvider {

constructor(
url: string | FetchRequest,
network?: Networkish,
Expand Down
22 changes: 15 additions & 7 deletions src/lacchain-signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import {
getAddress,
Transaction,
TransactionLike,
TransactionRequest
TransactionRequest,
} from 'ethers';

import { LacchainTransactionRequest } from './lacchain-transaction-request';


export class LacchainSigner extends Wallet {

constructor(
privateKey: string | SigningKey,
provider: Provider,
Expand All @@ -25,11 +23,17 @@ export class LacchainSigner extends Wallet {
super(privateKey, provider);
}

async signTransaction(transactionRequest: TransactionRequest): Promise<string> {
async signTransaction(
transactionRequest: TransactionRequest,
): Promise<string> {
// Replace any Addressable or ENS name with an address
const { to, from } = await resolveProperties({
to: transactionRequest.to ? resolveAddress(transactionRequest.to, this.provider) : undefined,
from: transactionRequest.from ? resolveAddress(transactionRequest.from, this.provider) : undefined,
to: transactionRequest.to
? resolveAddress(transactionRequest.to, this.provider)
: undefined,
from: transactionRequest.from
? resolveAddress(transactionRequest.from, this.provider)
: undefined,
});

if (to != null) {
Expand All @@ -52,7 +56,11 @@ export class LacchainSigner extends Wallet {

const btx = Transaction.from(
<TransactionLike<string>>(
new LacchainTransactionRequest(transactionRequest, this._aNodeAddress, this._aExpirationTime)
new LacchainTransactionRequest(
transactionRequest,
this._aNodeAddress,
this._aExpirationTime,
)
),
);

Expand Down
84 changes: 60 additions & 24 deletions src/lacchain-transaction-request.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,72 @@
import { AbiCoder, AccessListish, AddressLike, BigNumberish, BlockTag, TransactionRequest }
from 'ethers';


import {
AbiCoder,
AccessListish,
AddressLike,
BigNumberish,
BlockTag,
TransactionRequest,
} from 'ethers';

export class LacchainTransactionRequest implements TransactionRequest {

constructor(
private _aOriginalTransactionRequest: TransactionRequest,
private _aNodeAddress: string,
private _aExpirationTime: number
private _aExpirationTime: number,
) {}

get data(): any | string {
return this._aOriginalTransactionRequest.data + AbiCoder.defaultAbiCoder().encode(
["address", "uint256"],
[this._aNodeAddress, this._aExpirationTime]
).substring(2);;
return (
this._aOriginalTransactionRequest.data +
AbiCoder.defaultAbiCoder()
.encode(
['address', 'uint256'],
[this._aNodeAddress, this._aExpirationTime],
)
.substring(2)
);
}

get chainId(): any | BigNumberish { return 0; }
get chainId(): any | BigNumberish {
return 0;
}

get type(): any | number { return this._aOriginalTransactionRequest.type; }
get to(): any | AddressLike { return this._aOriginalTransactionRequest.to; }
get from(): any | AddressLike { return this._aOriginalTransactionRequest.from; }
get nonce(): any | number { return this._aOriginalTransactionRequest.nonce; }
get gasLimit(): any | BigNumberish { return this._aOriginalTransactionRequest.gasLimit; }
get gasPrice(): any | BigNumberish { return this._aOriginalTransactionRequest.gasPrice; }
get maxPriorityFeePerGas(): any | BigNumberish { return this._aOriginalTransactionRequest.maxPriorityFeePerGas; }
get maxFeePerGas(): any | BigNumberish { return this._aOriginalTransactionRequest.maxFeePerGas; }
get value(): any | BigNumberish { return this._aOriginalTransactionRequest.value; }
get accessList(): any | AccessListish { return this._aOriginalTransactionRequest.accessList; }
get customData(): any { return this._aOriginalTransactionRequest.customData; }
get blockTag(): undefined | BlockTag { return this._aOriginalTransactionRequest.blockTag; }
get enableCcipRead(): undefined | boolean { return this._aOriginalTransactionRequest.enableCcipRead; }
get type(): any | number {
return this._aOriginalTransactionRequest.type;
}
get to(): any | AddressLike {
return this._aOriginalTransactionRequest.to;
}
get from(): any | AddressLike {
return this._aOriginalTransactionRequest.from;
}
get nonce(): any | number {
return this._aOriginalTransactionRequest.nonce;
}
get gasLimit(): any | BigNumberish {
return this._aOriginalTransactionRequest.gasLimit;
}
get gasPrice(): any | BigNumberish {
return this._aOriginalTransactionRequest.gasPrice;
}
get maxPriorityFeePerGas(): any | BigNumberish {
return this._aOriginalTransactionRequest.maxPriorityFeePerGas;
}
get maxFeePerGas(): any | BigNumberish {
return this._aOriginalTransactionRequest.maxFeePerGas;
}
get value(): any | BigNumberish {
return this._aOriginalTransactionRequest.value;
}
get accessList(): any | AccessListish {
return this._aOriginalTransactionRequest.accessList;
}
get customData(): any {
return this._aOriginalTransactionRequest.customData;
}
get blockTag(): undefined | BlockTag {
return this._aOriginalTransactionRequest.blockTag;
}
get enableCcipRead(): undefined | boolean {
return this._aOriginalTransactionRequest.enableCcipRead;
}
}
80 changes: 58 additions & 22 deletions src/lacchain-transaction.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,67 @@
import { AccessList, Signature, Transaction, TransactionLike } from 'ethers';



export class LacchainTransaction implements TransactionLike {

constructor(private _aOriginalTx: Transaction, private _aHashTx: string) {}
constructor(
private _aOriginalTx: Transaction,
private _aHashTx: string,
) {}

get hash(): null | string {
return this._aHashTx;
}

get type(): null | number { return this._aOriginalTx.type; }
get typeName(): null | string { return this._aOriginalTx.typeName; }
get to(): null | string { return this._aOriginalTx.to; }
get nonce(): number { return this._aOriginalTx.nonce; }
get gasLimit(): bigint { return this._aOriginalTx.gasLimit; }
get gasPrice(): null | bigint { return this._aOriginalTx.gasPrice; }
get maxPriorityFeePerGas(): null | bigint { return this._aOriginalTx.maxPriorityFeePerGas; }
get maxFeePerGas(): null | bigint { return this._aOriginalTx.maxFeePerGas; }
get data(): string { return this._aOriginalTx.data; }
get value(): bigint { return this._aOriginalTx.value; }
get chainId(): bigint { return this._aOriginalTx.chainId; }
get signature(): null | Signature { return this._aOriginalTx.signature || null; }
get accessList(): null | AccessList { return this._aOriginalTx.accessList }
get unsignedHash(): string { return this._aOriginalTx.unsignedHash; }
get from(): null | string { return this._aOriginalTx.from; }
get fromPublicKey(): null | string { return this._aOriginalTx.fromPublicKey; }
get serialized(): string { return this._aOriginalTx.serialized; }
get unsignedSerialized(): string { return this._aOriginalTx.unsignedSerialized; }
get type(): null | number {
return this._aOriginalTx.type;
}
get typeName(): null | string {
return this._aOriginalTx.typeName;
}
get to(): null | string {
return this._aOriginalTx.to;
}
get nonce(): number {
return this._aOriginalTx.nonce;
}
get gasLimit(): bigint {
return this._aOriginalTx.gasLimit;
}
get gasPrice(): null | bigint {
return this._aOriginalTx.gasPrice;
}
get maxPriorityFeePerGas(): null | bigint {
return this._aOriginalTx.maxPriorityFeePerGas;
}
get maxFeePerGas(): null | bigint {
return this._aOriginalTx.maxFeePerGas;
}
get data(): string {
return this._aOriginalTx.data;
}
get value(): bigint {
return this._aOriginalTx.value;
}
get chainId(): bigint {
return this._aOriginalTx.chainId;
}
get signature(): null | Signature {
return this._aOriginalTx.signature || null;
}
get accessList(): null | AccessList {
return this._aOriginalTx.accessList;
}
get unsignedHash(): string {
return this._aOriginalTx.unsignedHash;
}
get from(): null | string {
return this._aOriginalTx.from;
}
get fromPublicKey(): null | string {
return this._aOriginalTx.fromPublicKey;
}
get serialized(): string {
return this._aOriginalTx.serialized;
}
get unsignedSerialized(): string {
return this._aOriginalTx.unsignedSerialized;
}
}
25 changes: 13 additions & 12 deletions src/test/e2e/deploy-and-tx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,45 @@ import { LacchainProvider } from '../../lacchain-provider';
import { LacchainSigner } from '../../lacchain-signer';
import { aPrivateKey, anExpirationTime, testAddresses } from '../fixtures';



describe('e2e Provider & Signer re', () => {

dotenv.config();

const { RPC_URL, NODE_ADDRESS, TRUSTED_FORWARDER } = env;


const signer: LacchainSigner = new LacchainSigner(
aPrivateKey,
new LacchainProvider(RPC_URL!),
NODE_ADDRESS!,
anExpirationTime
anExpirationTime,
);
console.log("set network")
console.log('set network');
const _deployContract = async () => {
const contractFactory = new ContractFactory(
aTestContract.abi,
aTestContract.bytecode,
signer
signer,
);

const contract = await contractFactory.deploy(signer.address, TRUSTED_FORWARDER!);


const contract = await contractFactory.deploy(
signer.address,
TRUSTED_FORWARDER!,
);

return await contract.deploymentTransaction()?.wait();
};

test('Deploy & Transaction re', async () => {
const txReceipt = await _deployContract();
const contractAddress = txReceipt?.contractAddress || '';
console.log(contractAddress)
console.log(contractAddress);
expect(contractAddress).toBeTruthy();

const contract = new Contract(contractAddress, aTestContract.abi, signer);

await (await contract.add(testAddresses[0], testAddresses[1])).wait();

expect(await contract.exists(testAddresses[0], testAddresses[1])).toEqual(true);
expect(await contract.exists(testAddresses[0], testAddresses[1])).toEqual(
true,
);
}, 100000000);
});
Loading
Loading