How Can I Automatically Modify A State? - corda

I have a flow from Party A to Party B where I save a NEW state.
Shortly after that, Party B starts a new flow with some extra identifiable info to the state and sends it back to Party A as EDITED.
Does this have to be 2 separate flows? Or can Party B add the extra info to the state during the responder?
It would probably end up triggering multiple responders something like this:
Party A Initiate -> Party B
Party B Modify + Respond -> Party A
Party A Verify + Respond -> Party B
Party B Verify -> Party A
Party A finalises transaction
If this isn't possible, is it possible to trigger the EDITED flow as soon as the NEW is complete? e.g.
Party A Initiate NEW -> Party B
Party B Verify + Respond -> Party A
Party A finalises NEW transaction/state
//Automatically:
Party B Initiate EDIT -> Party A
Party A Verify + Respond -> Party B
Party B finalises EDIT transaction/state
Could you have a service that listens for NEW and starts the EDITED flow as soon as the NEW is complete?

1- You can't modify a state in the responder, because the initiator already signed the state; meaning the initiator is testifying about the authenticity of certain data.
2- This should happen in 2 flows and you can automate that using SchedulableState:
- Documentation
- Example CorDapp
- More explanation and exercise/solution

Related

Sending received money (money is an example) from A to send it to B

I'm fairly new to DLT technologies and dove a bit in Corda. I'm not sure to understand everything well yet so here is my question that i tried to answer myself (using NotaryChangeFlow). Please correct me.
Problem setup :
I'm node A. I share facts with node B and node C. They don't share any fact.
For node B, we have notary B tracking our transactions.
For node C, we have notary C tracking our transactions.
Problem :
If B sends me let's say 5€.
How can I use those 5€ to send it to C
My solution:
A and B creates a transaction updating both states + updating notary B state.
A changes notary B to notary C.
A consumes his state shared with B and sends money to the facts he shared with C using notary C as validator.
A sends money to C.
That way : B knows A used 5€ and C knows 5€ has been added to A balance and is then transfered to him.
Is this the right way?
Thanks!
Yes, you are correct. Let me just reiterate to make it a little more clear. States in Corda are associated with a particular notary and can only be spent with that specific notary. If there is a need to spend a state at a different notary, a Notary Change Transaction is performed first. In a Notary Change Transaction, the state in question is spent at the current notary and reissued with the new notary.
All of this is done to ensure Notaries are able to do their job of preventing double-spending attempts in the network. Any notary other than the one where a state is being transacted would not have any information regarding the previous transaction of a state and would not be able to able to prevent double-spending attempts without that information.
So now in your case, B wants to send the $5 to A using notary N1 and now A wants to send the same $5 to C using notary N2. This will be a two-step process:
A does a Notary Change Transaction, where he spends the $5 state at N1 and reissues the state at N2. All this is taken care of by the library flow NotaryChangeFlow.
Now once the notary has been changed A can now construct a transaction to spend the state at notary N2.
On the statement B know $5 has been used by A, you need to either add A as a participant/ observer for him to be notified of any updates. Generally, this is not a requirement for cash since once I have to send the money to another party, I am not supposed to know what he does with it. But if that's a requirement for some use case the cordapp needs to be designed accordingly.

Is there a way that a Party can be notified that a Flow has been completed?

Taking as an example the flow described in the Corda documentation (see here), how can Bob receive the notification that the transaction he just signed has been completed, without polling his own vault?
Does a specific callback exist?
I need that the CorDapp running on Bob node communicates to another system the status of the transaction in real-time
Thanks a lot
Two ways you could achieve this:
1. Subscribe to update using Client
cordaRPCOPS.vaultTrack(<YourState>.class).getUpdates().subscribe( update -> {
update.getProduced().forEach(stateAndRef -> {
// Action to be Performed on State Update
});
});
2. Subscribe to update using CordaService:
getServiceHub().getVaultService().trackBy(<YourState>.class).getUpdates().subscribe( update -> {
update.getProduced().forEach(stateAndRef -> {
// Action to be Performed on State Update
});
});
In addition to Ashutosh's answer,
Inside a SpringBoot webserver that identifies an API to start your flow, you can use proxy.startTrackedFlowDynamic() (where proxy is your node's RPC connection); it returns a FlowProgressHandle which you can use to subscribe to flow events.

asterisk queue_log late COMPLETEAGENT

I am trying to write a wallboard for my asterisk server. This wallboard will process the queue_log file in /var/log/asterisk.
Here is a scenario in question:
1) A customer calls out call center. Let his number be 44556677889900 and our number 8881234567890.
2) The customer enters the queue 210.
3) Agent 1 takes the call.
4) Agent 1 decides that the call should go to another queue. And transfers it to queue 209
5) Agent 2 takes the call.
6) Agent 2 terminates the call after talking with the customer. (When Agent 2 is talking on the phone Agent 1 is idle and available for a new call.
7) Normally Agent 1 ended his call at 4th step, but the log with COMPLETEAGENT appears just now, even the agent is available since 4th step
Here is the output in the queue_log:
1550582529|1550582516.26480|210|NONE|DID|8881234567890 * 1. step*
1550582529|1550582516.26480|210|NONE|ENTERQUEUE||44556677889900|1 * 2. step*
1550582531|1550582516.26480|210|Test Agent 1|CONNECT|2|1550582529.26493|2 3. step
1550582536|1550582536.26498|209|NONE|DID| ** 4. step**
1550582536|1550582536.26498|209|NONE|ENTERQUEUE||9991|1 4. step
1550582539|1550582536.26498|209|Test Agent 2|CONNECT|3|1550582536.26499|2 5. step
1550582543|1550582536.26498|209|Test Agent 2|COMPLETECALLER|3|4|1 6. step
1550582549|1550582516.26480|210|Test 1|COMPLETEAGENT|2|18|1 7. step
As mentioned in the 7th step, Agent 1 if available for new calls after he transfers the call to queue 209. (In fact if a new call comes, the system send the call to Agent 1). However the log "COMPTELEAGENT" appears only when the customer disconnects.
This makes my wallboard think that Agent 1 is busy even he is not. And worse if he received a new call before Agent 2 finishes, everything gets more complicated.
Questions:
1) How it is possible to make the system send the COMPLETEAGENT at step 4 ?
2) Why is ATTENDEDTRANSFER log missing ? (Not related to this problem directly but can also be connected)
Asterisk Version: 13.22.0
Freepbx 14.0.5.25
Thank you in advance.
1) System should not send COMPLEATEAGENT at 4, becuase thoose event should be sent AFTER END of call.
That event is created by QUEUE, not by AGENT. From queue's point of view call not yet finished.
If you want it be finished, do transfer of LEGA, not queue's LEG.
2)Transfer subsystem not related to queue subsystem and SHOULD NOT be related in any realible PBX. You can write your own if you want.
Side notes
no point parse queue_log, much simpler setup queue_log in mysql or other db and read it.
you can write your own queue system using Async AGI.
you can add as many logs as you want by using dialplan CEL or UserEvents.

Asterisk - Pre-emption calls

I would like to have pre-emption calls in Asterisk. With this I mean that if user A has priority/access-level 1 and wants to talk to user B, how could it preempt the call that user B is already having with user C which has only priority/access-level 2?
Does anyone know if this is supported by Asterisk or how this could be implemented?
Any idea would be very welcome.
No, it not supported by asterisk.
But yes, it can be implemented using dialplan+some script magic. Complexity is high and require expert or guru skill.
Short plan is following:
check if B is in call (need use DEVICE_STATE or GROUP functions)
check if B in call with lower priority caller( ASTDB or REALTIME or fastagi script)
wisper both(or only B) party that now have priority call. For that need read about asterisk auto-dialout and wisper.
wait till B press confirmation key(features.conf)
transfer both B&C to new extension, bridge A&B, play hold for C.
deal with restore C connection if needed.

retain original caller id on Call transfer on asterisk

I am running a B2C outbound Campaign on VicidialNow C.E 1.1 as Asterisk Server / SIP Server.
The call is made from server to customer and connected to agents waiting for calls. The agents transfers the call to third party (not a blind transfer). The 3rd party sees the Caller ID of agent.
Now, what I want is to display the caller id or the phone number of the customer to the 3rd party.
I Googled and searched over SO, found this sendrpid=pai to add on sip.conf file. but this functionality only supports on 1.4 or upgraded version.
scenario:
Agent calls the Customer's phone ex 12123344 and call is received. Agent puts Customer on hold and dials Mr XX, another phone number (not the extension of sip server) ex 21214433. The conference call is made(customer, agent and Mr. XX are in conference). I want Mr. XX to see the Customers Number asap the Customer is Connected to the conference.
Capture the incoming CID information into a channel variable when the call first comes in:
exten => foo,1,Set(ORIG_CID=${CALLERID(all)})
... then set the CID just before you dial to be the contents of the channel variable.

Resources