From 3c136328de1e85c9bb9c8ce0954f9488bad011b6 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 24 Aug 2018 15:54:22 -0400 Subject: [PATCH] Updated the README to include the transaction details --- README.md | 64 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 77c7309..25e14b3 100644 --- a/README.md +++ b/README.md @@ -45,27 +45,59 @@ The gas relayer service needs to be running, and configured correctly to process -## Additional notes -How to send a message to this service (all accounts and privatekeys should be replaced by your own test data) +## Using the gas relayer + +### The relayer +A node that wants to act as a relayer only needs to have a geth node with whisper enabled, and an account with ether to process the transactions. This account and node need to be configured in `./config/config.js`. + +The relayer will be subscribed to receive messages in a specific symkey (this will change in the future to use ENS), and will reply back to both availability and transaction requests + +### The user + +#### Sending a message to the gas relayer network (all accounts and privatekeys should be replaced by your own test data) ``` -shh.post({symKeyID: SYM_KEY, sig: WHISPER_KEY_ID, ttl: 1000, powTarget: 1, powTime: 20, topic: TOPIC_NAME, payload: PAYLOAD_BYTES}); -``` -- `SYM_KEY` must contain the whisper symmetric key used. It is shown on the console when running the service with `node`. With the provided configuration you can use the value: -``` -0xd0d905c1c62b810b787141430417caf2b3f54cffadb395b7bb39fdeb8f17266b` +shh.post({ + symKeyID: SYM_KEY, // If requesting availability + pubKey: PUBLIC_KEY_ID, // If sending a transaction + sig: WHISPER_KEY_ID, + ttl: 1000, + powTarget: 1, + powTime: 20, + topic: TOPIC_NAME, + payload: PAYLOAD_BYTES +}).then(......) ``` +- `symKeyID: SYM_KEY` must contain the whisper symmetric key used. It is shown on the console when running the service with `node`. With the provided configuration you can use the symmetric key `0xd0d905c1c62b810b787141430417caf2b3f54cffadb395b7bb39fdeb8f17266b`. Only used when asking for relayer availability. +- `pubKey: PUBLIC_KEY_ID`. After asking for availability, once the user decides on a relayer, it needs to set the `pubKey` attribute with the relayer public key (received in the availability reply in the `sig` attribute of the message). - `WHISPER_KEY_ID` represents a keypair registered on your node, that will be used to sign the message. Can be generated with `web3W.shh.newKeyPair()` - `TOPIC_NAME` must contain one of the topic names generated based on converting the contract name to hex, and taking the first 8 bytes. For the provided configuration the following topics are available: - - IdentityGasRelay: `0x4964656e` - - SNTController: `0x534e5443` -- `PAYLOAD_BYTES` a hex string that contains the identity/contract address to invoke and the web3 encoded abi function invocation plus parameters. If we were to execute `callGasRelayed(address,uint256,bytes,uint256,uint256,uint256,address,bytes)` (part of the IdentityGasRelay) in contract `0x692a70d2e424a56d2c6c27aa97d1a86395877b3a`, with these values: `"0x11223344556677889900998877665544332211",100,"0x00",1,10,20,"0x1122334455112233445511223344551122334455"`, "0x1122334455", `PAYLOAD_BYTES` can be prepared as follows: +- `PAYLOAD_BYTES` a hex string that contains details on the operation to perform. +#### Polling for gas relayers +TODO + + + +#### Sending transaction details + +Sending a transaction is similar to the previous operation, except that we send the message to an specific node, we use the action `transaction`, and also we send a `encodedFunctionCall` with the details of the transaction to execute. + +From the list of relayers received via whisper messages, you need to extract the `message.sig` to obtain the `pubKey`. This value is used to send the transaction to that specific relayer. + +`encodedFunCall` is the hex data used obtained from `web3.eth.abi.encodeFunctionCall` for the specific function we want to invoke. + +If we were to execute `callGasRelayed(address,uint256,bytes,uint256,uint256,uint256,address,bytes)` (part of the IdentityGasRelay) in contract `0x692a70d2e424a56d2c6c27aa97d1a86395877b3a`, with these values: `"0x11223344556677889900998877665544332211",100,"0x00",1,10,20,"0x1122334455112233445511223344551122334455"`, "0x1122334455", `PAYLOAD_BYTES` can be prepared as follows: ``` - +// The following values are created obtained when polling for relayers const whisperKeyPairID = await web3W.shh.newKeyPair(); -const jsonAbi = ABIOfIdentityGasRelay.filter(x => x.name == "callGasRelayed")[0]; +const relayerPubKey = "0xRELAYER_PUBLIC_KEY_HERE"; +// ... +// ... +const jsonAbi = ABIOfIdentityGasRelay.find(x => x.name == "callGasRelayed"); const funCall = web3.eth.abi.encodeFunctionCall(jsonAbi, [ @@ -80,7 +112,7 @@ const funCall = web3.eth.abi.encodeFunctionCall(jsonAbi, ]); const msgObj = { - symKeyID: "0xd0d905c1c62b810b787141430417caf2b3f54cffadb395b7bb39fdeb8f17266b", + pubKey: relayerPubKey, sig: whisperKeyPairID, ttl: 1000, powTarget: 1, @@ -88,8 +120,9 @@ const msgObj = { topic: "0x4964656e", payload: web3.utils.toHex({ 'contract': "0x692a70d2e424a56d2c6c27aa97d1a86395877b3a", - 'encodedFunctionCall': funCall, 'address': web3.eth.defaultAccount + 'action': 'transaction', + 'encodedFunctionCall': funCall, }) }; @@ -100,4 +133,9 @@ web3.shh.post(msgObj) console.log(err); }); -``` \ No newline at end of file +``` + + +#### Valid operations +TODO +