-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JSON RPC point for generating exit proofs
- Loading branch information
1 parent
a298d0e
commit 8aa1f52
Showing
10 changed files
with
90 additions
and
0 deletions.
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 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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package jsonrpc | ||
|
||
import ( | ||
"github.com/0xPolygon/polygon-edge/types" | ||
) | ||
|
||
// bridgeStore interface provides access to the methods needed by bridge endpoint | ||
type bridgeStore interface { | ||
GenerateExitProof(exitID, epoch, checkpointBlock uint64) ([]types.Hash, error) | ||
} | ||
|
||
// Bridge is the bridge jsonrpc endpoint | ||
type Bridge struct { | ||
store bridgeStore | ||
} | ||
|
||
// GenerateExitProof generates exit proof for given exit event | ||
func (b *Bridge) GenerateExitProof(exitID, epoch, checkpointBlock BlockNumber) (interface{}, error) { | ||
return b.store.GenerateExitProof(uint64(exitID), uint64(epoch), uint64(checkpointBlock)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package jsonrpc | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/hashicorp/go-hclog" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBridgeEndpoint(t *testing.T) { | ||
store := newMockStore() | ||
|
||
dispatcher := newDispatcher( | ||
hclog.NewNullLogger(), | ||
store, | ||
&dispatcherParams{ | ||
chainID: 0, | ||
priceLimit: 0, | ||
jsonRPCBatchLengthLimit: 20, | ||
blockRangeLimit: 1000, | ||
}, | ||
) | ||
|
||
mockConnection, _ := newMockWsConnWithMsgCh() | ||
|
||
msg := []byte(`{ | ||
"method": "bridge_generateExitProof", | ||
"params": ["0x0001", "0x0001", "0x0002"], | ||
"id": 1 | ||
}`) | ||
|
||
data, err := dispatcher.HandleWs(msg, mockConnection) | ||
require.NoError(t, err) | ||
|
||
resp := new(SuccessResponse) | ||
require.NoError(t, json.Unmarshal(data, resp)) | ||
require.Nil(t, resp.Error) | ||
require.NotNil(t, resp.Result) | ||
} |
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