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

Refacto onstreamcreate and create in index [SBK-335] #64

Open
alexisnsns opened this issue Oct 25, 2023 · 0 comments
Open

Refacto onstreamcreate and create in index [SBK-335] #64

alexisnsns opened this issue Oct 25, 2023 · 0 comments
Assignees

Comments

@alexisnsns
Copy link
Contributor

alexisnsns commented Oct 25, 2023

This refactored code below throws some errors like 'no account' error when calling create or 'hash undefined' on streamcreate;
Not ready for prod but can be used as a draft.

` // new create function
// async create(
// token: Address,
// amountPerSecond: bigint,
// reason?: string,
// startTime?: number,
// accountOverride?: Address
// ): Promise {
// if (!accountOverride && !this.walletClient?.account)
// throw new Error("No account");

// const account =
// accountOverride || (this.walletClient?.account?.address ?? "0x0");

// const args: Array<number | string | bigint | Address | ByteArray> = [
// token,
// amountPerSecond,
// ];
// if (startTime) {
// args.push(reason ? stringToHex(reason) : "");
// args.push(startTime);
// } else if (reason) {
// args.push(stringToHex(reason));
// }

// // Step 1: Run the transaction
// const hash = await this.walletClient?.writeContract({
// chain: null,
// address: this.address,
// abi: StreamManagerContractType.abi as Abi,
// functionName: "create_stream",
// args,
// account,
// });

// console.log("writeContract params:", {
// chain: null,
// address: this.address,
// abi: StreamManagerContractType.abi,
// functionName: "create_stream",
// args,
// account,
// });

// if (hash === undefined)
// throw new Error("Error while processing transaction. Hash undefined.");

// // Step 2: Wait for transaction to be confirmed
// const receipt = await this.publicClient.waitForTransactionReceipt({
// hash: hash,
// });

// if (!receipt || !receipt.logs || receipt.logs.length === 0) {
// throw new Error("Transaction failed or logs are missing");
// }

// // Step 3: Use the last log for creating the Stream instance
// const lastLog = receipt.logs[receipt.logs.length - 1];

// return Stream.fromEventLog(
// this,
// lastLog,
// this.publicClient,
// this.walletClient
// );
// }

// new onstreamcreated
// onStreamCreated(
// handleStream: (stream: Stream) => null,
// creator?: Address
// ): void {
// const onLogs = (logs: Log[]) => {
// Promise.all(
// logs.map((log: Log) =>
// Stream.fromEventLog(this, log, this.publicClient, this.walletClient)
// .then(handleStream)
// .catch(console.error)
// )
// );
// };

// this.publicClient.watchContractEvent({
// address: this.address,
// abi: StreamManagerContractType.abi as Abi,
// eventName: "StreamCreated",
// args: creator ? { creator } : {},
// onLogs,
// });
// }
`

@vany365 vany365 changed the title Refacto onstreamcreate and create in index Refacto onstreamcreate and create in index [SBK-335] Oct 25, 2023
@alexisnsns alexisnsns self-assigned this Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant