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

add dagstore lib with http call #61

Closed
wants to merge 5 commits into from
Closed
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
29 changes: 24 additions & 5 deletions examples/app-ofa-private/ofa-private.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,30 @@ pragma solidity ^0.8.8;
import "suave-std/suavelib/Suave.sol";
import "suave-std/Context.sol";

library DagStore {
function get(bytes32 id) internal returns (bytes memory) {
bytes memory body = abi.encodePacked('{"jsonrpc":"2.0","method":"batches.Pull","params":["', id, '"],"id":1}');
string[] memory headers = new string[](1);
headers[0] = "Content-Type: application/json";
Suave.HttpRequest memory request = Suave.HttpRequest({
url: "http://localhost:8000",
method: "GET",
headers: headers,
body: body,
withFlashbotsSignature: false
});
return Suave.doHTTPRequest(request);
}
}

contract OFAPrivate {
// Struct to hold hint-related information for an order.
struct HintOrder {
Suave.DataId id;
bytes hint;
}

event HintEvent(Suave.DataId id, bytes hint);
event HintEvent(Suave.DataId id, bytes hint, bytes res);

event BundleEmitted(string bundleRawResponse);

Expand Down Expand Up @@ -43,14 +59,17 @@ contract OFAPrivate {
return hintOrder;
}

function emitHint(HintOrder memory order) public {
emit HintEvent(order.id, order.hint);
function emitHint(HintOrder memory order, bytes memory dagResult) public {
emit HintEvent(order.id, order.hint, dagResult);
}

// Function to create a new user order
function newOrder(uint64 decryptionCondition) external returns (bytes memory) {
HintOrder memory hintOrder = saveOrder(decryptionCondition);
return abi.encodeWithSelector(this.emitHint.selector, hintOrder);

bytes memory testRes = DagStore.get(keccak256("testkey"));

return abi.encodeWithSelector(this.emitHint.selector, hintOrder, testRes);
}

// Function to match and backrun another dataRecord.
Expand All @@ -64,7 +83,7 @@ contract OFAPrivate {
dataRecords[1] = hintOrder.id;
Suave.confidentialStore(hintOrder.id, "mevshare:v0:mergedDataRecords", abi.encode(dataRecords));

return abi.encodeWithSelector(this.emitHint.selector, hintOrder);
return abi.encodeWithSelector(this.emitHint.selector, hintOrder, bytes("undefined"));
}

function emitMatchDataRecordAndHintCallback(string memory bundleRawResponse) external {
Expand Down
Loading