-
Notifications
You must be signed in to change notification settings - Fork 13
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
migrate from eggroll to rollmelette #48
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
db35454
migrate from eggroll to rollmelette
ZzzzHui dfd9a03
fix frontend for the migration
ZzzzHui 1898dbd
Use input kind in-line
guidanoli f55b913
fix populate script
ZzzzHui 09e3995
Add `pnpm-lock.yaml` to `.prettierignore`
guidanoli f52c3d1
Fix inspect response processing
guidanoli 8cd505a
Fix typo in "Sponsor bounty" page
guidanoli de5c9e4
Fix JSON name of Go struct field
guidanoli c2c7a44
Fix advance request encoding
guidanoli 4c361a0
Fix back-end debug logs
guidanoli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,91 +3,99 @@ package cmd | |
import ( | ||
"bugless/shared" | ||
"context" | ||
"encoding/json" | ||
"log" | ||
"math/big" | ||
"os/exec" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/gligneul/eggroll" | ||
"github.com/gligneul/eggroll/eggeth" | ||
"github.com/gligneul/eggroll/eggtypes" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/gligneul/rollmelette" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var sendArgs struct { | ||
accountIndex uint32 | ||
fromAddress string | ||
} | ||
|
||
var sendCmd = &cobra.Command{ | ||
Use: "send", | ||
Short: "Send an advance-state input to the contract", | ||
} | ||
|
||
func sendDo(send func(context.Context, *eggroll.Client, eggeth.Signer) (int, error)) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer cancel() | ||
|
||
client, signer, err := eggroll.NewDevClient(ctx, shared.Codecs()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if sendArgs.accountIndex != 0 { | ||
err := signer.(*eggeth.MnemonicSigner).SetAccount(sendArgs.accountIndex) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
var addressBook = rollmelette.NewAddressBook() | ||
|
||
inputIndex, err := send(ctx, client, signer) | ||
var dappAddress = "0x70ac08179605AF2D9e75782b8DEcDD3c22aA4D0C" | ||
|
||
func sendDo(inputKind shared.InputKind, payload any, send func(string, context.Context) ([]byte, error)) { | ||
payloadJson, err := json.Marshal(payload) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Printf("added input %v", inputIndex) | ||
|
||
result, err := client.WaitFor(ctx, inputIndex) | ||
input := shared.Input{ | ||
Kind: inputKind, | ||
Payload: payloadJson, | ||
} | ||
inputJson, err := json.Marshal(input) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
inputJsonStr := hexutil.Encode(inputJson) | ||
|
||
if result.Status == eggtypes.CompletionStatusAccepted { | ||
log.Print("input accepted") | ||
} else { | ||
log.Print("input not accepted") | ||
} | ||
|
||
for _, voucher := range result.Vouchers { | ||
log.Printf("voucher to %v with payload 0x%v", | ||
voucher.Destination, common.Bytes2Hex(voucher.Payload)) | ||
} | ||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer cancel() | ||
|
||
for _, logMsg := range result.Logs() { | ||
log.Printf("contract: %v", logMsg) | ||
output, err := send(inputJsonStr, ctx) | ||
if err != nil { | ||
log.Fatal(string(output), err) | ||
} | ||
log.Printf("input added\n%s", output) | ||
} | ||
|
||
func sendEther(txValue *big.Int, input any) { | ||
sendDo(func(ctx context.Context, c *eggroll.Client, s eggeth.Signer) (int, error) { | ||
return c.SendEther(ctx, s, txValue, input) | ||
func sendEther(txValue *big.Int, inputKind shared.InputKind, payload any) { | ||
sendDo(inputKind, payload, func(inputJsonStr string, ctx context.Context) ([]byte, error) { | ||
cmd := exec.CommandContext(ctx, | ||
"cast", "send", | ||
"--unlocked", "--from", sendArgs.fromAddress, | ||
"--value", txValue.String(), | ||
addressBook.EtherPortal.String(), // TO | ||
"depositEther(address,bytes)", // SIG | ||
dappAddress, inputJsonStr, // ARGS | ||
) | ||
return cmd.CombinedOutput() | ||
}) | ||
} | ||
|
||
func sendInput(input any) { | ||
sendDo(func(ctx context.Context, c *eggroll.Client, s eggeth.Signer) (int, error) { | ||
return c.SendInput(ctx, s, input) | ||
func sendInput(inputKind shared.InputKind, payload any) { | ||
sendDo(inputKind, payload, func(inputJsonStr string, ctx context.Context) ([]byte, error) { | ||
cmd := exec.CommandContext(ctx, | ||
"cast", "send", | ||
"--unlocked", "--from", sendArgs.fromAddress, | ||
addressBook.InputBox.String(), // TO | ||
"addInput(address,bytes)(bytes32)", // SIG | ||
dappAddress, inputJsonStr, // ARGS | ||
) | ||
return cmd.CombinedOutput() | ||
}) | ||
} | ||
|
||
func sendDAppAddress() { | ||
sendDo(func(ctx context.Context, c *eggroll.Client, s eggeth.Signer) (int, error) { | ||
return c.SendDAppAddress(ctx, s) | ||
sendDo("", "", func(inputJsonStr string, ctx context.Context) ([]byte, error) { | ||
cmd := exec.CommandContext(ctx, | ||
"cast", "send", | ||
"--unlocked", "--from", sendArgs.fromAddress, | ||
addressBook.AppAddressRelay.String(), // TO | ||
"relayDAppAddress(address)", // SIG | ||
dappAddress, // ARGS | ||
) | ||
return cmd.CombinedOutput() | ||
}) | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(sendCmd) | ||
|
||
sendCmd.PersistentFlags().Uint32VarP(&sendArgs.accountIndex, | ||
"account-index", "a", 0, "Forge account index when sending the transaction") | ||
sendCmd.PersistentFlags().StringVarP(&sendArgs.fromAddress, | ||
"from-address", "f", "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", | ||
"Sender address when sending the transaction") | ||
Comment on lines
-91
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: instead of using account index, we now use address as argument directly |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @gligneul
Do you think something like waitForInput function is a good helper function to replace the
WaitFor
function above?Similarly, to implement the stateRun function, seems this getNodeState function would be a good helper, but it's not exported.