mirror of https://github.com/hyperledger/besu
add JSON-RPC method to call /storeraw on GoQuorum enclave (#1859)
* added GoQuorumStoreRawPrivateTransaction that can send a payload to Tessera for storing Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>pull/1888/head
parent
a30d8accb1
commit
1de067b473
@ -0,0 +1,29 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.enclave.types; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
||||
public class GoQuorumStoreRawRequest { |
||||
private final String payload; |
||||
|
||||
public GoQuorumStoreRawRequest(@JsonProperty(value = "payload") final String payload) { |
||||
this.payload = payload; |
||||
} |
||||
|
||||
public String getPayload() { |
||||
return payload; |
||||
} |
||||
} |
@ -0,0 +1,31 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.enclave.types; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
||||
public class StoreRawResponse { |
||||
private final String key; |
||||
|
||||
@JsonCreator |
||||
public StoreRawResponse(@JsonProperty("key") final String key) { |
||||
this.key = key; |
||||
} |
||||
|
||||
public String getKey() { |
||||
return key; |
||||
} |
||||
} |
@ -0,0 +1,65 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv; |
||||
|
||||
import static org.apache.logging.log4j.LogManager.getLogger; |
||||
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcEnclaveErrorConverter.convertEnclaveInvalidReason; |
||||
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.DECODE_ERROR; |
||||
|
||||
import org.hyperledger.besu.enclave.GoQuorumEnclave; |
||||
import org.hyperledger.besu.enclave.types.StoreRawResponse; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; |
||||
import org.hyperledger.besu.ethereum.rlp.RLPException; |
||||
|
||||
import org.apache.logging.log4j.Logger; |
||||
|
||||
public class GoQuorumStoreRawPrivateTransaction implements JsonRpcMethod { |
||||
|
||||
private static final Logger LOG = getLogger(); |
||||
private final GoQuorumEnclave enclave; |
||||
|
||||
public GoQuorumStoreRawPrivateTransaction(final GoQuorumEnclave enclave) { |
||||
this.enclave = enclave; |
||||
} |
||||
|
||||
@Override |
||||
public String getName() { |
||||
return RpcMethod.GOQUORUM_STORE_RAW.getMethodName(); |
||||
} |
||||
|
||||
@Override |
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { |
||||
final Object id = requestContext.getRequest().getId(); |
||||
final String payload = requestContext.getRequiredParameter(0, String.class); |
||||
|
||||
try { |
||||
LOG.debug("sending payload " + payload); |
||||
final StoreRawResponse storeRawResponse = enclave.storeRaw(payload); |
||||
String enclaveLookupId = storeRawResponse.getKey(); |
||||
LOG.debug("got key from GoQuorum enclave " + enclaveLookupId); |
||||
return new JsonRpcSuccessResponse(id, enclaveLookupId); |
||||
} catch (final IllegalArgumentException | RLPException e) { |
||||
LOG.error(e); |
||||
return new JsonRpcErrorResponse(id, DECODE_ERROR); |
||||
} catch (final Exception e) { |
||||
return new JsonRpcErrorResponse(id, convertEnclaveInvalidReason(e.getMessage())); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue