export class PatriciaMerkleTreeDatasourceLive extends Effect.Service<PatriciaMerkleTreeDatasourceLive>()(
"PatriciaMerkleTreeDatasourceLive",
{
dependencies: [PatriciaTrie.Default],
effect: Effect.gen(function* () {
const trie = yield* PatriciaTrie.trie;
const insert = (address: string) =>
Effect.gen(function* () {
// return yield* new AlreadyExistsError({ address });
yield* Effect.tryPromise({
try: () => trie.insert(address, "0"),
catch: () => new AlreadyExistsError({ address }),
});
return trie.hash.toString("hex");
});
return {
insert,
};
}),
},
) {}
export class PatriciaMerkleTreeDatasourceLive extends Effect.Service<PatriciaMerkleTreeDatasourceLive>()(
"PatriciaMerkleTreeDatasourceLive",
{
dependencies: [PatriciaTrie.Default],
effect: Effect.gen(function* () {
const trie = yield* PatriciaTrie.trie;
const insert = (address: string) =>
Effect.gen(function* () {
// return yield* new AlreadyExistsError({ address });
yield* Effect.tryPromise({
try: () => trie.insert(address, "0"),
catch: () => new AlreadyExistsError({ address }),
});
return trie.hash.toString("hex");
});
return {
insert,
};
}),
},
) {}