Skip to content

Commit

Permalink
Add service alias example (#68)
Browse files Browse the repository at this point in the history
* Add service alias example

* Fix https
  • Loading branch information
ferranbt authored Aug 7, 2024
1 parent e67b54d commit 97201bb
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/mevm-confidential-store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This example features how to use the Confidential Store.
Run `Suave` in development mode:

```
$ suave --suave.dev
$ suave-geth --suave.dev
```

Execute the deployment script:
Expand Down
2 changes: 1 addition & 1 deletion examples/mevm-context/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The `suave-std` suite provides a high-level interface to the MEVM context with t
Run `Suave` in development mode:

```
$ suave --suave.dev
$ suave-geth --suave.dev
```

Execute the deployment script:
Expand Down
2 changes: 1 addition & 1 deletion examples/mevm-is-confidential/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This example shows how to use the IsConfidential precompile. This precompile ret
Run `Suave` in development mode:

```
$ suave --suave.dev
$ suave-geth --suave.dev
```

Execute the deployment script:
Expand Down
2 changes: 1 addition & 1 deletion examples/offchain-logs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract ExampleSuapp is Suapp {
Run `Suave` in development mode:

```
$ suave --suave.dev
$ suave-geth --suave.dev
```

Execute the deployment script:
Expand Down
2 changes: 1 addition & 1 deletion examples/onchain-callback/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Only logs emitted during the onchain execution are available for querying on the
Run `Suave` in development mode:

```
$ suave --suave.dev
$ suave-geth --suave.dev
```

Execute the deployment script:
Expand Down
3 changes: 1 addition & 2 deletions examples/onchain-state/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Example Suapp with OnChain state

This example shows how Suapps can update state of the smart contract on the Suave chain.
Expand All @@ -10,7 +9,7 @@ State variables updated during the confidential request are not updated on the s
Run `Suave` in development mode:

```
$ suave --suave.dev
$ suave-geth --suave.dev
```

Execute the deployment script:
Expand Down
3 changes: 1 addition & 2 deletions examples/private-library-confidential-store/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Example Suapp with a Private library

This example shows how Suapps can use private libraries stored in the confidential store that are not public in the Suave chain.
Expand All @@ -10,7 +9,7 @@ The private code is saved in the confidential store with the `registerContract`
Run `Suave` in development mode:

```
$ suave --suave.dev
$ suave-geth --suave.dev
```

Execute the deployment script:
Expand Down
3 changes: 1 addition & 2 deletions examples/private-library/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Example Suapp with a Private library

This example shows how Suapps can use private libraries that are not public in the Suave chain.
Expand All @@ -10,7 +9,7 @@ The private code is sent inside the confidential part of the confidential comput
Run `Suave` in development mode:

```
$ suave --suave.dev
$ suave-geth --suave.dev
```

Execute the deployment script:
Expand Down
2 changes: 1 addition & 1 deletion examples/private-suapp-key-gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is a variation of the [private-suapp-key](../private-suapp-key) example. Th
Run `Suave` in development mode:

```
$ suave --suave.dev
$ suave-geth --suave.dev
```

Execute the deployment script:
Expand Down
2 changes: 1 addition & 1 deletion examples/private-suapp-key/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This example shows how Suapps can store private keys in the confidential storage
Run `Suave` in development mode:

```
$ suave --suave.dev
$ suave-geth --suave.dev
```

Execute the deployment script:
Expand Down
17 changes: 17 additions & 0 deletions examples/service-alias/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Example Suapp that uses the service registry

This example shows how Suapps can use the Kettle service registry to resolve HTTP service aliases.

## How to use

Run `Suave` in development mode:

```
$ suave-geth --suave.dev --suave.service-alias example=https://example.com --suave.eth.external-whitelist='*'
```

Execute the deployment script:

```
$ go run main.go
```
9 changes: 9 additions & 0 deletions examples/service-alias/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import "github.com/flashbots/suapp-examples/framework"

func main() {
fr := framework.New()
fr.Suave.DeployContract("service-alias.sol/ServiceAlias.json").
SendConfidentialRequest("example", nil, nil)
}
25 changes: 25 additions & 0 deletions examples/service-alias/service-alias.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.8;

import "suave-std/suavelib/Suave.sol";
import "suave-std/Suapp.sol";

contract ServiceAlias is Suapp {
function exampleCallback() public {}

function example() public returns (bytes memory) {
Suave.HttpRequest memory request;
request.url = "example";
request.method = "GET";
request.timeout = 1000;

bytes memory response1 = Suave.doHTTPRequest(request);

// Make the request to the http endpoint
request.url = "https://example.com";
bytes memory response2 = Suave.doHTTPRequest(request);

require(keccak256(response1) == keccak256(response2), "Strings should be equal");
return abi.encodeWithSelector(this.exampleCallback.selector);
}
}
2 changes: 1 addition & 1 deletion examples/std-gateway-erc20/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This example features how a Suapp can use the [`Gateway.sol`](https://github.com
Run `Suave` in development mode:

```
$ suave --suave.dev
$ suave-geth --suave.dev
```

Export the JSON-RPC URL of the chain where the ERC20 contract is deployed:
Expand Down
2 changes: 1 addition & 1 deletion examples/std-transaction-signing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This example shows how to use the `suave-std` library to create and sign transac
Run `Suave` in development mode:

```
$ suave --suave.dev
$ suave-geth --suave.dev
```

Execute the deployment script:
Expand Down

0 comments on commit 97201bb

Please sign in to comment.