Skip to content

Commit

Permalink
Rename sendTransaction to sendConfidentialRequest (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt authored Mar 1, 2024
1 parent ca97abd commit c73e161
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 25 deletions.
6 changes: 3 additions & 3 deletions examples/app-ofa-private/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func main() {
log.Printf("Latest goerli block: %d", target)

// new dataRecord inputs
receipt := contract.SendTransaction("newOrder", []interface{}{target + 1}, bundleBytes)
receipt := contract.SendConfidentialRequest("newOrder", []interface{}{target + 1}, bundleBytes)

hintEvent := &HintEvent{}
if err := hintEvent.Unpack(receipt.Logs[0]); err != nil {
Expand All @@ -115,7 +115,7 @@ func main() {
log.Printf("Latest goerli block: %d", target)

// backrun inputs
receipt = contract.SendTransaction("newMatch", []interface{}{hintEvent.DataRecordId, target + 1}, backRunBundleBytes)
receipt = contract.SendConfidentialRequest("newMatch", []interface{}{hintEvent.DataRecordId, target + 1}, backRunBundleBytes)

matchEvent := &HintEvent{}
if err := matchEvent.Unpack(receipt.Logs[0]); err != nil {
Expand All @@ -127,7 +127,7 @@ func main() {
// Step 4. Emit the batch to the relayer and parse the output
fmt.Println("4. Emit batch")

receipt = contract.SendTransaction("emitMatchDataRecordAndHint", []interface{}{cfg.BuilderURL, matchEvent.DataRecordId}, backRunBundleBytes)
receipt = contract.SendConfidentialRequest("emitMatchDataRecordAndHint", []interface{}{cfg.BuilderURL, matchEvent.DataRecordId}, backRunBundleBytes)
bundleHash, err := decodeBundleEmittedOutput(receipt)
if err != nil {
log.Fatal(err)
Expand Down
8 changes: 4 additions & 4 deletions examples/build-eth-block/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func main() {
decryptionCondition := targetBlock + 1
allowedPeekers := []common.Address{
buildEthBlockAddress,
bundleContract.Address(),
ethBlockContract.Address()}
bundleContract.Raw().Address(),
ethBlockContract.Raw().Address()}
allowedStores := []common.Address{}
newBundleArgs := []any{
decryptionCondition,
Expand All @@ -59,7 +59,7 @@ func main() {
confidentialDataBytes, err := bundleContract.Abi.Methods["fetchConfidentialBundleData"].Outputs.Pack(bundleBytes)
maybe(err)

_ = bundleContract.SendTransaction("newBundle", newBundleArgs, confidentialDataBytes)
_ = bundleContract.SendConfidentialRequest("newBundle", newBundleArgs, confidentialDataBytes)
}

{ // Signal to the builder that it's time to build a new block
Expand All @@ -69,7 +69,7 @@ func main() {
FeeRecipient: common.Address{0x42},
}

_ = ethBlockContract.SendTransaction("buildFromPool", []any{payloadArgsTuple, targetBlock + 1}, nil)
_ = ethBlockContract.SendConfidentialRequest("buildFromPool", []any{payloadArgsTuple, targetBlock + 1}, nil)
maybe(err)
}
}
Expand Down
3 changes: 2 additions & 1 deletion examples/mevm-confidential-store/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import (

func main() {
fr := framework.New()
fr.Suave.DeployContract("confidential-store.sol/ConfidentialStore.json").SendTransaction("example", []interface{}{}, nil)
fr.Suave.DeployContract("confidential-store.sol/ConfidentialStore.json").
SendConfidentialRequest("example", []interface{}{}, nil)
}
2 changes: 1 addition & 1 deletion examples/mevm-context/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
func main() {
fr := framework.New()
fr.Suave.DeployContract("context.sol/ContextExample.json").
SendTransaction("example", nil, []byte{0x1})
SendConfidentialRequest("example", nil, []byte{0x1})
}
2 changes: 1 addition & 1 deletion examples/mevm-is-confidential/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
func main() {
fr := framework.New()
fr.Suave.DeployContract("is-confidential.sol/IsConfidential.json").
SendTransaction("example", nil, nil)
SendConfidentialRequest("example", nil, nil)
}
4 changes: 2 additions & 2 deletions examples/offchain-logs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ func main() {
fr := framework.New()
contract := fr.Suave.DeployContract("offchain-logs.sol/OffchainLogs.json")

receipt := contract.SendTransaction("example", nil, nil)
receipt := contract.SendConfidentialRequest("example", nil, nil)
if len(receipt.Logs) != 2 {
log.Fatal("two logs expected")
}

// emit the CCR but DO NOT leak the logs
receipt = contract.SendTransaction("exampleNoLogs", nil, nil)
receipt = contract.SendConfidentialRequest("exampleNoLogs", nil, nil)
if len(receipt.Logs) != 1 {
log.Fatal("only one log expected")
}
Expand Down
2 changes: 1 addition & 1 deletion examples/onchain-callback/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
func main() {
fr := framework.New()
fr.Suave.DeployContract("onchain-callback.sol/OnChainCallback.json").
SendTransaction("example", nil, nil)
SendConfidentialRequest("example", nil, nil)
}
2 changes: 1 addition & 1 deletion examples/onchain-state/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func main() {

fmt.Println("2. Send a confidential request that modifies the state")

contract.SendTransaction("example", nil, nil)
contract.SendConfidentialRequest("example", nil, nil)
val, ok := contract.Call("getState")[0].(uint64)
if !ok {
fmt.Printf("expected uint64")
Expand Down
4 changes: 2 additions & 2 deletions examples/private-library-confidential-store/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ func main() {
suapp := fr.Suave.DeployContract("lib-confidential-store.sol/PublicSuapp.json")

// Deploy the contract and get the bid id
receipt := suapp.SendTransaction("registerContract", nil, privateLibrary.Code)
receipt := suapp.SendConfidentialRequest("registerContract", nil, privateLibrary.Code)
event, _ := contractRegisteredABI.Inputs.Unpack(receipt.Logs[0].Data)
privateContractBidId := event[0].([16]byte)

// Use the private contract
suapp.SendTransaction("example", []interface{}{privateContractBidId}, nil)
suapp.SendConfidentialRequest("example", []interface{}{privateContractBidId}, nil)
}

var contractRegisteredABI abi.Event
Expand Down
2 changes: 1 addition & 1 deletion examples/private-library/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ func main() {

fr := framework.New()
fr.Suave.DeployContract("private-library.sol/PublicSuapp.json").
SendTransaction("example", nil, privateLibrary.Code)
SendConfidentialRequest("example", nil, privateLibrary.Code)
}
2 changes: 1 addition & 1 deletion examples/std-transaction-signing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func main() {
priv := "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291"

contract := fr.Suave.DeployContract("transaction-signing.sol/TransactionSigning.json")
receipt := contract.SendTransaction("example", nil, []byte(priv))
receipt := contract.SendConfidentialRequest("example", nil, []byte(priv))

// validate the signature
txnSignatureEvent, err := contract.Abi.Events["TxnSignature"].ParseLog(receipt.Logs[0])
Expand Down
14 changes: 7 additions & 7 deletions framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func GeneratePrivKey() *PrivKey {
}

type Contract struct {
*sdk.Contract
contract *sdk.Contract

clt *sdk.Client
kettleAddr common.Address
Expand Down Expand Up @@ -139,14 +139,14 @@ func (c *Contract) Call(methodName string) []interface{} {
}

func (c *Contract) Raw() *sdk.Contract {
return c.Contract
return c.contract
}

var executionRevertedPrefix = "execution reverted: 0x"

// SendTransaction sends the transaction and panics if it fails
func (c *Contract) SendTransaction(method string, args []interface{}, confidentialBytes []byte) *types.Receipt {
txnResult, err := c.Contract.SendTransaction(method, args, confidentialBytes)
// SendConfidentialRequest sends the confidential request to the kettle
func (c *Contract) SendConfidentialRequest(method string, args []interface{}, confidentialBytes []byte) *types.Receipt {
txnResult, err := c.contract.SendTransaction(method, args, confidentialBytes)
if err != nil {
// decode the PeekerReverted error
errMsg := err.Error()
Expand Down Expand Up @@ -276,7 +276,7 @@ func (c *Chain) DeployContract(path string) *Contract {
log.Printf("deployed contract at %s", receipt.ContractAddress.Hex())

contract := sdk.GetContract(receipt.ContractAddress, artifact.Abi, c.clt)
return &Contract{addr: receipt.ContractAddress, clt: c.clt, kettleAddr: c.kettleAddr, Abi: artifact.Abi, Contract: contract}
return &Contract{addr: receipt.ContractAddress, clt: c.clt, kettleAddr: c.kettleAddr, Abi: artifact.Abi, contract: contract}
}

func (c *Contract) Ref(acct *PrivKey) *Contract {
Expand All @@ -285,7 +285,7 @@ func (c *Contract) Ref(acct *PrivKey) *Contract {
cc := &Contract{
addr: c.addr,
Abi: c.Abi,
Contract: sdk.GetContract(c.addr, c.Abi, clt),
contract: sdk.GetContract(c.addr, c.Abi, clt),
}
return cc
}
Expand Down

0 comments on commit c73e161

Please sign in to comment.