Accountid & PublicKey returns different transactions for 0.0.1261794 - hedera-hashgraph

I am using hedera offical api in code, for accountid 0.0.1261794 getting 2 transactions only where as publickkey e2cc4c84391f5d9fd74dcf8199fb0bcd9c629f4d9aaa223649aad2814c56e6ba associated with 0.0.1261794 accountid, return more than 20 transactions.
Account API -
https://mainnet-public.mirrornode.hedera.com/api/v1/accounts?account.id=0.0.1261794
Transaction API (AccountId) -
https://mainnet-public.mirrornode.hedera.com/api/v1/transactions?account.id=0.0.1261794
Transaction API (PublicKey) -
https://mainnet-public.mirrornode.hedera.com/api/v1/transactions?account.publickey=e2cc4c84391f5d9fd74dcf8199fb0bcd9c629f4d9aaa223649aad2814c56e6ba
As from explorer it's showing only two transactions.
https://hederaexplorer.io/search-details/account/0.0.1261794
Thanks
Umang

This other network explorer also confirms that only two transactions are associated with the account ID you provided: https://hashscan.io/#/mainnet/account/0.0.1261794
One possible reason for this behavior is that on Hedera the concepts of accounts and keys are separate. This means that:
a key pair (private/public keys) can be associated with more than one account.
an account can be multi-sig, meaning it can have multiple keys associated with it to authorize transactions. More details on this in the Hedera documentation: https://docs.hedera.com/guides/core-concepts/accounts#account-id

/transactions doesn’t really support filtering by account.publickey we probably should have returned status code 400 instead of treating it as if it’s just /transactions.
This will be fixed. Thanks for highlighting the issue.

Related

StoreKit: Transaction ID and Original Transaction ID Chaos

I've been struggling with this for some days now. I hope I get it now, but I wanted to check it with you.
For every transaction there is a SKPaymentTransaction. In a regular purchase, the property Original Transaction is empty. In a restore or auto renewal, Original transaction is the original transaction SKPaymentTransaction.
The tricky part in my opinion is the receipt received. So every transaction in the receipt contains a transaction_id and a original_transaction_id. In a one time purchase they are the same, in a subscription, the original_transaction_id is the transaction_id of the first transaction the user subscribed.
So my first question: If I want to check the validity of a purchase in the receipt -> The transactionID of the SKPayment transaction appears ONLY in the receipt, if it is not a restore or renewal. Otherwise the SKPaymentTransaction transactionID is NOT in the receipt. But since in these cases the SKPaymentTransaction has a property originalTransaction, originalTransaction.transactionID appears in the receipt. Correct?
And now the thing I have been struggling with, 2nd question: So the originalTransaction property of the SKPaymentTransaction has not necessarily anything to do with the original_transaction_id in the receipt, correct? I mean for a subscription with several renewals - If I restore them I get a SKPaymentTransaction with a transaction ID, which isn't in the receipt. Then I take instead the originalTransaction.transactionID of this SKPaymentTransaction and look for it in the receipt, but NOT in the original_transaction_id field but in the transaction_id field of the receipt, correct?
I hope I get it now..I really think the documentation is rather confusing here from Apple..
Restoring the transactions on your device will generate unique transaction_id's. So the original_transaction_id will not be found after this if you do it. The same happens on different devices, e.g. iPad, iPhone. the web_order_line_item_id will not change for these transactions if you need a stable identifier.
Yes, in your SKPaymentTransaction there is a property originalTransaction. You can find your original_transaction_id in the receipt. However it is not a good way to validate receipt, because it should be done using the server to avoid man in the middle attacks.
I would recommend you validating receipt through the server as Apple recommends.
There are a few of ready-to-go solutions, like ours - Apphud or RevenueCat.
Also I would recommend you reading articles about what is receipt validation and why it's needed: https://blog.apphud.com/receipt-validation/

Sql Server Service Broker - thorough, in-use example of externally activated console app

I need some guidance from anyone who has deployed a real-world, in-production application that uses the Sql Server Service Broker external activation mechanism (via the Service Broker External Activator from the Feature Pack).
Current mindset:
My specs are rather simple (or at least I think so), so I'm thinking of the following basic flow:
order-like entity gets inserted into a Table_Orders with state "confirmed"
SP_BeginOrder gets executed and does the following:
begins a TRANSACTION
starts a DIALOG from Service_HandleOrderState to Service_PreprocessOrder
stores the conversation handle (from now on PreprocessingHandle) in a specific column of the Orders table
sends a MESSAGE of type Message_PreprocessOrder containing the order id using PreprocessingHandle
ends the TRANSACTION
Note that I'm not ending the conversation, I don't want "fire-and-forget"
event notification on Queue_PreprocessOrder activates an instance of PreprocessOrder.exe (max concurrent of 1) which does the following:
begins a SqlTransaction
receives top 1 MESSAGE from Queue_PreprocessOrder
if message type is Message_PreprocessOrder (format XML):
sets the order state to "preprocessing" in Table_Orders using the order id in the message body
loads n collections of data of which computes an n-ary Carthesian product (via Linq, AFAIK this is not possible in T-SQL) to determine the order items collection
inserts the order items rows into a Table_OrderItems
sends a MESSAGE of type Message_PreprocessingDone, containing the same order id, using PreprocessingHandle
ends the conversation pertaining to PreprocessingHandle
commits the SqlTransaction
exits with Environment.Exit(0)
internal activation on Queue_HandleOrderState executes a SP (max concurrent of 1) that:
begins a TRANSACTION
receives top 1 MESSAGE from Queue_InitiatePreprocessOrder
if message type is Message_PreprocessingDone:
sets the order state to "processing" in Table_Orders using the order id in the message body
starts a DIALOG from Service_HandleOrderState to Service_ProcessOrderItem
stores the conversation handle (from now on ProcessOrderItemsHandle) in a specific column of Table_Orders
creates a cursor for rows in Table_OrderItems for current order id and for each row:
sends a MESSAGE of type Message_ProcessOrderItem, containing the order item id, using ProcessOrderItemsHandle
if message type is Message_ProcessingDone:
sets the order state to "processed" in Table_Orders using the order id in the message body
if message type is http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog (END DIALOG):
ends the conversation pertaining to conversation handle of the message
ends the TRANSACTION
event notification on Queue_ProcessOrderItem activates an instance of ProcessOrderItem.exe (max concurrent of 1) which does the following:
begins a SqlTransaction
receives top 1 MESSAGE from Queue_ProcessOrderItem
if message type is Message_ProcessOrderItem (format XML):
sets the order item state to "processing" in Table_OrdersItems using the order item id in the message body, then:
loads a collection of order item parameters
makes a HttpRequest to a URL using the parameters
stores the HttpResponse as a PDF on filesystem
if any errors occurred in above substeps, sets the order item state to "error", otherwise "ok"
performs a lookup in the Table_OrdersItems to determine if all order items are processed (state is "ok" or "error")
if all order items are processed:
sends a MESSAGE of type Message_ProcessingDone, containing the order id, using ProcessOrderItemsHandle
ends the conversation pertaining to ProcessOrderItemsHandle
commits the SqlTransaction
exits with Environment.Exit(0)
Notes:
specs specify MSSQL compatibility 2005 through 2012, so:
no CONVERSATION GROUPS
no CONVERSATION PRIORITY
no POISON_MESSAGE_HANDLING ( STATUS = OFF )
I am striving to achieve overall flow integrity and continuity, not speed
given that tables and SPs reside in DB1 whilst Service Broker objects (messages, contracts, queues, services) reside in DB2, DB2 is SET TRUSTWORTHY
Questions:
Are there any major design flaws in the described architecture ?
Order completion state tracking doesn't seem right. Is there a better method ? Maybe using QUEUE RETENTION ?
My intuition tells me that in no case whatsoever should the activated external exe terminate with an exit code other than 0, so there should be try{..}catch(Exception e){..} finally{ Environment.Exit(0) } in Main. Is this assumption correct ?
How would you organize error handling in DB code ? Is an error log table enough?
How would you organize error handling in external exe C# code ? Same error logging
table ?
I've seen the SQL Server Service Broker Product Samples, but the Service Broker Interface seems overkill for my seemingly simpler case. Any alternatives for a simpler Service Broker object model ?
Any cross-version "portable" admin tool for Service Broker capable of at least draining poison messages ?
Have you any decent code samples for any of the above ?
Q: Are there any major design flaws in the described architecture ?
A: Couple of minor perks:
- waiting for an HTTP request to complete while holding open a transaction is bad. You can't achieve transactional consistency between a database and HTTP anyway, so don't risk to have a transaction stretch for minutes when the HTTP is slow. The typical pattern is to {begin tran/receive/begin conversation timer/commit} then issue the HTTP call w/o any DB xact. If the HTTP call succeeds then {begin xact/send response/end conversation/commit}. If the HTTP fails (or client crashes) then let the conversation time activate you again. You'll get a timer message (no body), you need to pick up the item id associated with the handle from your table(s).
Q: Order completion state tracking doesn't seem right. Is there a better method ? Maybe using QUEUE RETENTION ?
A: My one critique of your state tracking is the dependency on scanning the order items to determine that the current processed one is the last one (5.3.4). For example you could add the information that this is the 'last' item to be processed in the item state so you know, when processing it, that you need to report the completion. RETENTION is only useful in debugging or when you have logic that require to run 'logical rollback' and to compensating actions on conversation error.
Q: My intuition tells me that in no case whatsoever should the activated external exe terminate with an exit code other than 0, so there should be try{..}catch(Exception e){..} finally{ Environment.Exit(0) } in Main. Is this assumption correct ?
A: The most important thing is for the activated process to issue a RECEIVE statement on the queue. If it fails to do so the queue monitor may enter the notified state forever. Exit code is, if I remember correctly, irrelevant. As with any background process is important to catch and log exceptions, otherwise you'll never even know it has a problem when it start failing. In addition to disciplined try/catch blocks, Hookup Application.ThreadException for UI apps and AppDomain.UnhandledException for both UI and non-UI apps.
Q: How would you organize error handling in DB code ? Is an error log table enough?
A: I will follow up later on this. Error log table is sufficient imho.
Q: How would you organize error handling in external exe C# code ? Same error logging table ?
A: I created bugcollect.com exactly because I had to handle such problems with my own apps. The problem is more than logging, you also want some aggregation and analysis (at least detect duplicate reports) and suppress floods of errors from some deployment config mishap 'on the field'. Truth be told nowadays there are more options, eg. exceptron.com. And of course I think FogBugs also has logging capabilities.
Q: I've seen the SQL Server Service Broker Product Samples, but the Service Broker Interface seems overkill for my seemingly simpler case. Any alternatives for a simpler Service Broker object model ?
finally, an easy question: Yes, it is overkill. There is no simple model.
Q: Any cross-version "portable" admin tool for Service Broker capable of at least draining poison messages ?
A: The problem with poison messages is that the definition of poison message changes with your code: the poison message is whatever message breaks the current guards set in place to detect it.
Q: Have you any decent code samples for any of the above ?
A: No
One more point: try to avoid any reference from DB1 to DB2 (eg. 4.3.4 is activated in DB1 and reads the items table from DB2). This creates cross DB dependencies which break when a) one DB is offline (eg. for maintenance) or overloaded or b) you add database mirroring for HA/DR and one DB fails over. Try to make the code to work even if DB1 and DB2 are on different machines (and no linked servers). If necessary, add more info to the messages payload. And if you architect it that way that DB2 can be on a different machine and even multiple DB2 machines can exists to scale out the HTTP/PDF writing work.
And finally: this design will be very slow. I'm talking low tens messages per second slow, with so many dialogs/messages involved and everything with max_queue_readers 1. This may or may not be acceptable for you.

Return value for correct session?

I'm working on a project in dead ASP (I know :( )
Anyway it is working with a kdb+ database which is major overkill but not my call. Therefore to do inserts etc we're having to write special functions so they can be handled.
Anyway we've hit a theoretical problem and I'm a bit unsure how it should be dealt with in this case.
So basically you register a company, when you submit validation will occur and the page will be processed, inserting new values to the appropriate tables. Now at this stage I want to pull ID's from the tables and use them in the session for further registration screens. The user will never add a specific ID of course so it needs to be pulled from the database.
But how can this be done? I'm particularly concerned with 2 user's simultaneously registering, how can I ensure the correct ID is passed back to the correct session?
Thank you for any help you can provide.
Instead of having the ID set at the point of insert, is it possible for you to "grab" an ID value before hand, and then use that value throughout the process?
So:
Start the registration.
System connects to the database, creates an ID (perhaps from an ID table) and Stores in ASP Session.
Company registers.
You validate and insert data into DB (including the ID session)
The things you put in the Session(...) collection is only visible to that session (i.e. the session is used only by the browser windows on one computer). The session is identified by a GUID value that is stored in a cookie on the client machine. It is "safe" to store your IDs there (other users won't be able to read them easily) .
either your id can include date and time - so it will be example - id31032012200312 - but if you still think that 2 people can register at the same type then I would use recordset locks liek the ones here - http://www.w3schools.com/ado/prop_rs_locktype.asp
To crea ids like above in asp you do - replace(date(),"/","") ' and then same with time with ":"
Thanks

Chatter : getDeleted EntitySubscription and FeedLike

There are no triggers available on EntitySubscription and FeedLike objects, so there's no way available to log deletion of these objects.
Is there a way to determine the deleted entity subscription and feedlike records for a specific period of time ie say a api call that gives last xhrs deleted records.
I tried using ALL ROWS and Isdeleted=true clause with EntitySubscription to retrieve deleted records, but it's not working.
You can do this via the getDeleted call in the SOAP API, but i don't think that's exposed in apex anywhere.

Locking several SQL Server records

My scenario is this. I have a single entity composed of several rows in several tables. Conceptually this can be seen as a single document. When a user opens a "document", all associated rows must be locked, much like Windows locks a file when it is opened. As the "document" may be open until the user chooses to close it, I don't think transactions are a viable solution. The only solution I have come up with is to have a boolean 'Locked' field in every table and to set this to True on relevant rows when a "document" is opened. I'm using SQL Server 2008 R2.
Any ideas?
You can use application locking.
Assuming each document has a unique ID, a portable solution is to use a single table that knows about every locked document:
CREATE TABLE DocumentLocked (
doc_id INT PRIMARY KEY,
session_id <some type>,
lock_acquired DATETIME
);
When you want to lock a document, try to insert the id of the document in question along with some session ID identifying the owning session and the time you locked it. If it fails, the document is already locked. The session ID and lock_acquired columns don't play a role in the locking. It just helps display useful information to the user, like, "This document was locked by Rubio at 9:43 am."
One problem with this approach is that crashed clients can leave documents locked forever, so you need some application-level mechanism to clobber locks. The lock_acquired column can serve as a timeout mechanism by requiring the application to update the time every so often, and using this to detect stale locks.
If you don't care about portability, go with #demas's answer.
In you case "locking" is probably part of your business processes and low-level transaction mechanism should not be used for that purpose. So you're right, you need 'Locked' field either in all participating tables or a single one in a special "lock"-table.

Resources