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

Query multiple bids #69

Merged
merged 4 commits into from
Oct 31, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ^1.21
go-version: "1.22"
id: go

- name: Check out code into the Go module directory
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ^1.22
go-version: "1.22"
id: go

- name: Check out code into the Go module directory and submodules
Expand Down
28 changes: 25 additions & 3 deletions examples/mevm-confidential-store/confidential-store.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,41 @@ import "suave-std/suavelib/Suave.sol";
contract ConfidentialStore {
function callback() external {}

function example() external returns (bytes memory) {
function example(string memory namespace) external returns (bytes memory) {
address[] memory allowedList = new address[](1);
allowedList[0] = address(this);

Suave.DataRecord memory dataRecord = Suave.newDataRecord(10, allowedList, allowedList, "namespace");
Suave.DataRecord memory dataRecord = Suave.newDataRecord(10, allowedList, allowedList, namespace);

Suave.confidentialStore(dataRecord.id, "key1", abi.encode(1));
Suave.confidentialStore(dataRecord.id, "key2", abi.encode(2));

bytes memory value = Suave.confidentialRetrieve(dataRecord.id, "key1");
require(keccak256(value) == keccak256(abi.encode(1)));

Suave.DataRecord[] memory allShareMatchBids = Suave.fetchDataRecords(10, "namespace");
Suave.DataRecord[] memory allShareMatchBids = Suave.fetchDataRecords(10, namespace);
require(allShareMatchBids.length == 1);

return abi.encodeWithSelector(this.callback.selector);
}

function example2(string memory namespace) external returns (bytes memory) {
// Add a new entry for the confidential store combination (10, namespace)
address[] memory allowedList = new address[](1);
allowedList[0] = address(this);

Suave.newDataRecord(10, allowedList, allowedList, namespace);

Suave.DataRecord[] memory allShareMatchBids = Suave.fetchDataRecords(10, namespace);
require(allShareMatchBids.length == 2);

return abi.encodeWithSelector(this.callback.selector);
}

function query(string memory namespace) external returns (bytes memory) {
Suave.DataRecord[] memory allShareMatchBids = Suave.fetchDataRecords(10, namespace);
require(allShareMatchBids.length == 2);

return abi.encodeWithSelector(this.callback.selector);
}
}
9 changes: 7 additions & 2 deletions examples/mevm-confidential-store/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (

func main() {
fr := framework.New()
fr.Suave.DeployContract("confidential-store.sol/ConfidentialStore.json").
SendConfidentialRequest("example", []interface{}{}, nil)

namespace := framework.RandomString(10)
ctr := fr.Suave.DeployContract("confidential-store.sol/ConfidentialStore.json")

ctr.SendConfidentialRequest("example", []interface{}{namespace}, nil)
ctr.SendConfidentialRequest("example2", []interface{}{namespace}, nil)
ctr.SendConfidentialRequest("query", []interface{}{namespace}, nil)
}
13 changes: 13 additions & 0 deletions framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package framework
import (
"context"
"crypto/ecdsa"
"crypto/rand"
"encoding"
"encoding/hex"
"encoding/json"
Expand Down Expand Up @@ -349,3 +350,15 @@ func GatewayAddr() string {
}
return "host.docker.internal"
}

func RandomString(length int) string {
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
b := make([]byte, length)
if _, err := rand.Read(b); err != nil {
panic(fmt.Errorf("failed to generate random string: %w", err))
}
for i := range b {
b[i] = charset[b[i]%byte(len(charset))]
}
return string(b)
}
Loading