How to watch all transactions without filter for avalanche smart contract events? - web3js

I use the following code and Web3.py to listen for smart contract events but I want to listen for all transactions without a filter so that I can then decode the input data and filter based on methods not events.
def main():
contract = w3.eth.contract(address=A_CONTRACT, abi=A_ABI)
eventFilter = contract.events.EventName().createFilter(fromBlock="latest")
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(asyncio.gather(log_loop(eventFilter, 2)))
finally:
loop.close()
In the Avalanche Smart Contract ABI I have "events" and "functions". For example:
{
"anonymous": false,
"inputs": [
...
],
"name": "StartGame",
"type": "event"
},
...
{
"inputs": [
...
],
"name": "reinforceDefense",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
In Snow Trace Avalanche Blockchain explorer there is a methods column. For example,
Can use any library web3py web3js etc. How do I listen for all transactions to a smart contract (not just specific smart contract events)?

Related

ARM Template deployment - CosmosDB provision fails with - Request rate is large. More Request Units may be needed, so no changes were made

I tried deploying cosmosDB and when I first create it I get this error -
"Request rate is large. More Request Units may be needed, so no changes were made"
After redeploying it works.
But the initial creation doesn't.
I extended the throughput to 50000 (autoscale)
and 10000 with fixed size.
Is there another option to extend the RUs?
"type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers",
"apiVersion": "2020-03-01",
"name": "
"dependsOn":
],
"properties": {
"resource": {
"id": "subscriptions",
"indexingPolicy": {
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*"
}
],
"excludedPaths": [
{
"path": "/\"_etag\"/?"
}
],
"spatialIndexes": [
{
"path": "/*",
"types": ["Point", "LineString", "Polygon", "MultiPolygon"]
}
]
},
"partitionKey": {
"paths": ["/partitionKey"],
"kind": "Hash"
},
"uniqueKeyPolicy": {
"uniqueKeys": []
},
"conflictResolutionPolicy": {
"mode": "LastWriterWins",
"conflictResolutionPath": "/_ts"
}
},
"options": {
"autoscaleSettings": {
"maxThroughput": 50000
}
}
}
The error message indicates that there was a large number of requests hitting the master partition for your account. This can be caused by other clients querying the database resource to list containers or querying containers to get it's properties. It can also happen when you are deploying a large number of Cosmos resources at the same time. This is mostly a transient issue and is hard to reproduce.
Your arm template for this container looks correct. I'm guessing you've purposely removed the name and depends on parameters.
I would update the api-version to 2020-04-01 however. There are issues with 2020-03-01 with autoscale and that api-version is going to be deprecated in the future.

Azure Logic Apps parameters - how to use it?

For a few weeks now, there is a new "Parameter" section in the Designer of Logic Apps. We can create parameters and use these parameters in the Logic Apps:
Unfortunately, there are two things that are missing (or not working yet):
We are not able to set the "current value" of a parameter (as shown below, the field Actual Value is grayed)
When we export the Logic App as an ARM template, parameters are not used in the ARM template as ARM parameters.
Am I missing something or is it just due to the fact that there are features not yet deployed?
I'm not either sure how default/actual values should work in the Logic App designer but for the export of the ARM template with the (designer) parameters I'm using the last build of LogicAppTemplateCreator and it works for me.
The template snippet contains "paramDateFrom" parameter with its default value and it is used in the parameters section of ARM:
...
"paramDateFrom": {
"type": "string",
"defaultValue": "2019-12-19"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2016-06-01",
"name": "[parameters('logicAppName')]",
"location": "[parameters('logicAppLocation')]",
"dependsOn": [],
"properties": {
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"DateFrom": {
"defaultValue": "[parameters('paramDateFrom')]",
"type": "String"
}
},
...
The template parameters file contains the actual value:
...
"parameters": {
"paramDateFrom": {
"value": "2019-12-20"
}

EventGrid Trigger - How to set clienttrackingid from triggerbody?

In a microservice environment where requests span multiple services including eventgrid i'd like to configure an end-to-end logging with correlationid.
Inspired by this blog https://toonvanhoutte.wordpress.com/2018/08/05/end-to-end-correlation-across-logic-apps/
How can i configure the EventGrid triggers clientTrackingId with my correlationnr from Events data payload?
Checkout my definition below which does not work.
If i substitute "#{coalesce(json(triggerBody().Data)?.CorrelationNr, guid())}" with a string value or even "#parameters('$connections')['azureeventgrid']['connectionId']" it works like a charm.
"triggers": {
"When_a_resource_event_occurs": {
"correlation": {
"clientTrackingId": "#{coalesce(json(triggerBody().Data)?.CorrelationNr, guid())}"
},
"inputs": {
"body": {
"properties": {
"destination": {
"endpointType": "webhook",
"properties": {
"endpointUrl": "#{listCallbackUrl()}"
}
},
"filter": {
"includedEventTypes": [
"webhook.sp.updated"
]
},
"topic": "/subscriptions/xxxx/resourceGroups/xxx/providers/Microsoft.EventGrid/topics/WebHookManager"
}
},
"host": {
"connection": {
"name": "#parameters('$connections')['azureeventgrid']['connectionId']"
}
},
"path": "/subscriptions/#{encodeURIComponent('xxx')}/providers/#{encodeURIComponent('Microsoft.EventGrid.Topics')}/resource/eventSubscriptions",
"queries": {
"x-ms-api-version": "2017-06-15-preview"
}
},
"splitOn": "#triggerBody()",
"type": "ApiConnectionWebhook"
}
}
Logic App does not trigger. No Error message.
Please check the description about clientTrackingId, and your logic app no runs history is because your triggerBody() doesn't have CorrelationNr with the definition you show.
Actually your Event Grid trigger has detected the event, it just couldn't run with the logic. You could go to the EVALUATION and check the trigger history. It's because the value is null, then it won't run.
If you use HTTP request trigger, you could set the x-my-custom-correlation-id header. or set any key-value in the json body, then set the clientTrackingId with like #{coalesce(json(triggerBody())['keyname'], guid())}.
And if you are using some trigger without header, you have to point the value with string or other parameter like you said the connectionid or the parameter value you custom like below.
So the point is the clientTrackingId must be set before it runs and value could be obatined.

Where can I provide filter for Azure Service Bus Topic Subscription from my logic app

I've created a service bus, topic, and subscription to that topic in Azure. I have a logic app that is triggered when a message arrives but I need to apply a filter (or rule?) to that subscription where it looks for a particular value in the message header before the logic app processes the message. I don't see anywhere in the logic app or in the Azure portal to create filters for the subscriptions. What mechanism exists to create a filter for a subscription?
How did you create your topic subscription? did you use ARM Templates?
When you are creating the Subscription, you can add a SqlFilter to the rule applied in the topic subscription.
The ARM Template below (taken from here) shows you how to add a SqlFilter to the Rule in a Topic Subsctiption
"resources": [{
"apiVersion": "[variables('sbVersion')]",
"name": "[parameters('serviceBusNamespaceName')]",
"type": "Microsoft.ServiceBus/Namespaces",
"location": "[variables('location')]",
"sku": {
"name": "Standard",
},
"resources": [{
"apiVersion": "[variables('sbVersion')]",
"name": "[parameters('serviceBusTopicName')]",
"type": "Topics",
"dependsOn": [
"[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespaceName'))]"
],
"properties": {
"path": "[parameters('serviceBusTopicName')]"
},
"resources": [{
"apiVersion": "[variables('sbVersion')]",
"name": "[parameters('serviceBusSubscriptionName')]",
"type": "Subscriptions",
"dependsOn": [
"[parameters('serviceBusTopicName')]"
],
"properties": {},
"resources": [{
"apiVersion": "[variables('sbVersion')]",
"name": "[parameters('serviceBusRuleName')]",
"type": "Rules",
"dependsOn": [
"[parameters('serviceBusSubscriptionName')]"
],
"properties": {
"filterType": "SqlFilter",
"sqlFilter": {
"sqlExpression": "StoreName = 'Store1'",
"requiresPreprocessing": "false"
},
"action": {
"sqlExpression": "set FilterTag = 'true'"
}
}
}]
}]
}]
}]
You need to add your filter using Sql like expressions in the properties member of the rules sub-resource
e.g.
"sqlExpression": "YourMessageProperty='YourExpectedValue'",
If you are not using ARM Templates, the Service Bus Explorer allows you to remove the default subscription rule and create a new one with your own SqlFilter.
HTH

Logic Apps variable in replace expression

I have a Logic Apps instance with a variable AddedPoKey set out of parsed JSON
"Set_PO_Key_variable_": {
"inputs": {
"name": "AddedPoKey",
"value": "#{body('Parse_JSON')?['poKey']}"
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "SetVariable"
},
I want to use the value to set the Id in a RESTful API collection resource. I have not been able to get it to work, though I am sure it should. I am possible not finding the best MS documentation on this and if any could be pointed out to me, I would appreciate it. I have tried:
"Set_Po_Lin_Add_url_": {
"inputs": {
"name": "CreatePoLineResourceUrl",
"value": "#{replace('https://api.plex.com/EDI/sales-orders/{PoKey}/lines','{PoKey}',triggerBody()['AddedPoKey'])}"
},
"runAfter": {
"Set_PO_Key_variable_": [
"Succeeded"
]
},
"type": "SetVariable"
}
Which results in InvalidTemplate. Unable to process template language expressions in action 'Set_Po_Lin_Add_url_' inputs at line '1' and column '2459': 'The template language expression 'replace('https://api.plex.com/EDI/sales-orders/{PoKey}/lines','{PoKey}',triggerBody()['AddedPoKey'])' cannot be evaluated because property 'AddedPoKey' doesn't exist, available properties are 'ContentData, ContentType, ContentTransferEncoding, Properties, MessageId, To, ReplyTo, ReplyToSessionId, Label, ScheduledEnqueueTimeUtc, SessionId, CorrelationId, SequenceNumber, LockToken, TimeToLive'. Please see https://aka.ms/logicexpressions for usage details.'.
and then
"#{replace('https://api.plex.com/EDI/sales-orders/{PoKey}/lines','{PoKey}',variables('AddedPoKey')}"
which works.
Note that https://aka.ms/logicexpressions had been my main references, but does not even have the word "variable" on the page at this time.

Resources