I'm wondering if there any way to find transaction by input/output address.
In REST API Reference GET /state/{address} is mentioned, but I don't understand what I get in response:
{
"data": "oXiAODM1OGFjYzgyY2FmYmY1ZjUzZmNjNDcwMzE0YTMzYjk1N2ViMzE0ZmI1OWU3MmVkNDVkNjNhMTZjZDAxMjc5NTg1OTliY2Q3ZDQ0ZmI4NWUxZDBmZGY5ZmJmYTU3N2FhZjgyYWNlNzBkMDVmZDJmYWIzMzNhMTYzMDM5Y2U3NDZ2MjAxOC0wOS0xOSBhdCAxMzoxMTo0OQ==",
"head": "22972511836daa61bef7b9b987760579bcc249809a6f2ff59b3050e989bc2ace116d5c4c1cea10fba0aad25f200bb117e6958765be1047a67493590c07b2603c",
"link": "http://xxx.xxx.xxx.xxx:8080/state/4536b54af36b6dbad85af2bf228500aaa7f89d11cf0bac0f3290a5977bae443d74d692?head=22972511836daa61bef7b9b987760579bcc249809a6f2ff59b3050e989bc2ace116d5c4c1cea10fba0aad25f200bb117e6958765be1047a67493590c07b2603c"
}
I've tried to decode data from response, figured out that it is Base64 encoded and that it contains only payload of transaction.
Is there any way to get the ID of transaction?
You can fetch a Sawtooth transaction with the REST API using
GET /transactions/{transaction_id}
You need to know the transaction ID. The client submits and creates the transaction ID and would know it.
The transaction ID is also listed in the transaction header for each transaction in a blockchain.
You can also list all transactions with GET /transactions
Yes, the data is base64-encoded. After decoding, you need to deserialize. The deserializing method is up to the Transaction Processor that processes the transaction. Common serialization methods are Protobuf and CBOR.
Related
so I am looking into the postmates API and I have been able to create a delivery. This was great, I also setup a webhook url with ngrok to test the response from postmates but I am totally stumped as to how to determine when the pickup was actually completed and the dropoff/delivery was actually completed.
I saved all of the responses in a database and each time I did the test delivery, I received exactly 70 calls from the webhook endpoint. And each time 47 of them were in regards to the 'kind': 'event.delivery_status'. Here are the stats:
THIS IS ALL IN TEST MODE WITH THE SANDBOX...
11 of those are 'status':'pickup_complete'
14 of those are 'status':'pickup'
11 of those are 'status':'dropoff'
11 of those are 'status':'delivered'
all of the webhook responses for status=delivered have a 'data.courier_imminent':false value.
I went to the webpage for the 'data.tracking_url' and when the webpage showed that the delivery was complete, I immediately updated the database to see how many records that I had saved and I was only at 32 total records. this means that the webhook was continuing to send me updates after it was supposedly complete.
Lastly, all of these statuses are not in order, they are totally random, in fact the 6th to last record that was received was a pickup_complete status..
The real question:
how will I know what is actually a picked=completed, delivered=complete etc..
You'll receive a webhook of type event.delivery_status. One of the field within the body of the payload will be {status: "delivered"}. This has been accurate so far. Postmates doesn't return adelivered_at` timestamp, but you could create your own timestamp and store it along with the delivery for reporting.
As for the number of webhooks, Postmates has a delivery robot (called robo) that moves as if it was a real postmate. You'll receive a lot of webhooks of type event.courier_update with the updated location.
I want to create an ethereum withdrawal system on my site. I know how to send transactions with web3and do other things but I have one problem. If you are trying to send transaction while you already have a processing transaction you will get {'code': -32000, 'message': 'known transaction: (txn hash)'} error. That means that I can't just process transactions without stopping. So how can I do it? Should I make a queue or something like that? I heard I can do it with promises but I don't know how.
I would like to get some data from a chaincode transaction (too complex for a query), but, as I see from the code, transactions return promises that don't resolve to values. In addition, chaincode has access to the current user's identity, and I don't know how to implement this in a query.
The Util class contains both invokeChainCode and queryChainCode methods, but the BusinessNetworkConnection class has only the submitTransaction transaction method that uses invokeChainCode and doesn't return any value.
What is the correct way of getting data from the chaincode, apart from copying and modifying the code for submitTransaction?
As far as I can understand your question, you wish to return some values from a transaction.
Assuming that the transaction is of Invoke Type (not query) then whatever you are returning from the chain code (for example shim.Success(someData);, it will be part of your transaction payload.)
So, in order to get that transaction payload from the transaction, you have to make sure its committed to the peer's ledger.
To be sure, just before you submit the transaction, you can subscribe to the transaction event using the given transaction id)
Ref:
https://github.com/hyperledger/fabric-samples/blob/release/balance-transfer/app/invoke-transaction.js#L90
EventHub : https://fabric-sdk-node.github.io/EventHub.html
Once you receive this event you can be sure that your transaction is successfully committed in the peer.
You can use the same transaction ID you can query a peer for the transaction block.
Ref : https://github.com/hyperledger/fabric-samples/blob/release/balance-transfer/app/query.js#L95
Channel.queryTransaction : https://fabric-sdk-node.github.io/Channel.html#queryTransaction__anchor
Once you get the transaction payload in JSON you can dig into the JSON and find the return value in proposal response part of the JSON payload.
[P.S. Assuming you are using Node JS SDK]
EDIT 1:
Hyperledger Fabric supports only 2 types of transactions on a broader level.
Invoke - If you send the proposal response to the orderer then your values (if any) are written to the state otherwise, any queried value are returned as a part of the proposal response payload.
Deploy - In case of Chaincode deployment transactions where the payload is just a chaincode binary.
So, in case you have read only transaction then you could just submit the transaction and get the proposal response payload from the peer(s). The proposal response itself is the result of your query invocation.
Today, I am thinking a simplified scenario as follows:
I have my own payment system and when user come to save money, I use a form to save transaction data in my own DB. Before saving my own record, I need call Bank payment system which has a Webservice API like
public boolean pay(userInfo userInfo, float money).
Based on the result returned, I determine whether save my own data or not.
My question is if after calling the Bank payment API, my own network is off, and no result back. How to determine whether I need to save my own Form record or not. Maybe bank payment system has already processed this transaction? How to make two part data synchronized?
We cannot change bank payment API because bank spec is fixed. Webservice API is SOAP or Restful
Your implementation may be something like this:
Always save transaction data to your database and mark it as "unprocessed".
Use separate "worker" process, that fetches all unprocessed transaction from your database, and calls pay method of Bank payment system.
Accordingly to pay method result, choose to change/not change the status of the transaction.
Worker may by a scheduled process (each XX sec/minutes/etc) or some service that queries unprocessed transactions constantly (maybe with some delay between loops).
So in case of "no result" from Bank payment system, transaction state will not be changed and "pay" method will be retried on next worker run.
I have a mobile device that is constantly recording information. The information is stored on the device's local database. Every few minutes, the device will upload the data to a server through a REST API - sometimes the uploaded data corresponds to dozens of records from the same table. Right now, the server responds with
{status: "SAVED"}
if the data is saved to the server.
In the interest of being 100% sure that the data is actually uploaded (so the device won't attempt to upload it again), is that simple response enough? Or should I be hashing the incoming data and responding with it, or something similar? Perhaps I should send back the local row ids of the device's table's rows?
I think it's fine to have a very simple "SUCCESS" response if the entire request did indeed successfully save.
However, I think that when there is a problem, your response needs to include the IDs (or some other unique identifier) of the records that failed to save so that they can be queued to be resent.
If the same records fail multiple times, you might need to log the error or display it so that further action can be taken.
A successful response could be something as simple as:
<response>
<status>1</status>
</response>
An error response could be something like:
<response>
<status>0</status>
<errorRecords>
<id>441</id>
<id>8462</id>
<id>12</id>
</errorRecords>
</response>
You could get fancy and have different status codes that mean different, more specific messages.