Skip to content

Commit

Permalink
Query multiple bids (#69)
Browse files Browse the repository at this point in the history
* Query multiple bids

* Lock Go version in CI

* Follow lint

* Fix other CI
  • Loading branch information
ferranbt authored Oct 31, 2024
1 parent 97201bb commit 896ca67
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
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)
}

0 comments on commit 896ca67

Please sign in to comment.