@@ -12,10 +12,29 @@ import java.io.BufferedReader
1212import java.io.InputStreamReader
1313import java.net.HttpURLConnection
1414import java.net.URL
15+ // This class handles account_put_deploy RPC call
1516class PutDeployRPC {
1617 companion object {
1718 var methodURL: String = ConstValues .TESTNET_URL
1819 var putDeployCounter: Int = 0
20+ /*
21+ This function does account_put_deploy RPC call
22+ This function initiate the process of sending POST request with given parameter in JSON string format like this:
23+ {"id": 1,"method": "account_put_deploy","jsonrpc": "2.0","params":
24+ [{"header": {"account": "0152a685e0edd9060da4a0d52e500d65e21789df3cbfcb878c91ffeaea756d1c53",
25+ "timestamp": "2022-06-28T11:35:19.349Z","ttl":"1h 30m","gas_price":1,
26+ "body_hash":"798a65dae48dbefb398ba2f0916fa5591950768b7a467ca609a9a631caf13001","dependencies": [],
27+ "chain_name": "casper-test"},
28+ "payment": {"ModuleBytes": {"module_bytes": "","args":
29+ [["amount",{"bytes": "0400ca9a3b","cl_type":"U512","parsed":"1000000000"}]]}},
30+ "session": {"Transfer": {"args": [["amount",{"bytes": "04005ed0b2","cl_type":"U512","parsed":"3000000000"}],
31+ ["target",{"bytes": "015f12b5776c66d2782a4408d3910f64485dd4047448040955573aa026256cfa0a","cl_type":"PublicKey","parsed":"015f12b5776c66d2782a4408d3910f64485dd4047448040955573aa026256cfa0a"}],
32+ ["id",{"bytes": "010000000000000000","cl_type":{"Option": "U64"},"parsed":0}],["spender",{"bytes": "01dde7472639058717a42e22d297d6cf3e07906bb57bc28efceac3677f8a3dc83b","cl_type":"Key","parsed":{"Hash":"hash-dde7472639058717a42e22d297d6cf3e07906bb57bc28efceac3677f8a3dc83b"}}]]}},
33+ "approvals": [{"signer": "0152a685e0edd9060da4a0d52e500d65e21789df3cbfcb878c91ffeaea756d1c53",
34+ "signature": "016596f09083d32eaffc50556f1a5d22202e8927d5aa3267639aff4b9d3412b5ae4a3475a5da6c1c1086a9a090b0e1090db5d7e1b7084bb60b2fee3ce9447a2a04"}],
35+ "hash": "65c6ccdc5aacc9dcd073ca79358bf0b5115061e8d561b3e6f461a34a6c5858f0"}]}
36+ Then the PutDeployResult is retrieved by parsing JsonObject result taken from the RPC POST request
37+ */
1938 fun putDeploy (deploy : Deploy ) :String {
2039 val deployHash: String = deploy.hash
2140 val jsonStr: String = fromDeployToJsonString(deploy)
@@ -38,7 +57,6 @@ class PutDeployRPC {
3857 response.append(responseLine!! .trim { it <= ' ' })
3958 }
4059 val json = response.toString().toJson()
41-
4260 if (json.get(" error" ) != null ) {
4361 val message = json.get(" error" ).get(" message" )
4462 if (message == " invalid deploy: the approval at index 0 is invalid: asymmetric key error: failed to verify secp256k1 signature: signature error" ) {
@@ -58,14 +76,16 @@ class PutDeployRPC {
5876 }
5977 } else {
6078 val putDeployResult: PutDeployResult =
61- PutDeployResult .fromJsonObjectToGetAuctionInfoResult (json.get(" result" ) as JsonObject )
79+ PutDeployResult .fromJsonObjectToPutDeployResult (json.get(" result" ) as JsonObject )
6280 println (" Put deploy successfull with deploy hash:" + putDeployResult.deployHash)
6381 putDeployCounter = 0
6482 return putDeployResult.deployHash
6583 }
6684 return deployHash
6785 }
6886 }
87+ // This function does the work of turing a deploy object to a Json string, used as parameter to send for
88+ // POST method of the account_put_deploy RPC call.
6989 fun fromDeployToJsonString (deploy : Deploy ):String {
7090 val headerString: String = " \" header\" : {\" account\" : \" " + deploy.header.account + " \" ,\" timestamp\" : \" " + deploy.header.timeStamp + " \" ,\" ttl\" :\" " + deploy.header.ttl+ " \" ,\" gas_price\" :" + deploy.header.gasPrice+ " ,\" body_hash\" :\" " + deploy.header.bodyHash + " \" ,\" dependencies\" : [],\" chain_name\" : \" " + deploy.header.chainName + " \" }"
7191 val paymentJsonStr: String = " \" payment\" : " + ExecutableDeployItemHelper .toJsonString(deploy.payment)
0 commit comments