You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* [FABCN-403] Adds aroundTransaction hook
Signed-off-by: iMacTia <giuffrida.mattia@gmail.com>
* [FABC-403] A few more formatting fixes
Signed-off-by: iMacTia <giuffrida.mattia@gmail.com>
* [FABCN-403] Trying to fight with tabs...
Signed-off-by: iMacTia <giuffrida.mattia@gmail.com>
Co-authored-by: Matthew B White <mbwhite@users.noreply.github.com>
Copy file name to clipboardExpand all lines: docs/_jsdoc/tutorials/deep-dive-contract-interface.md
+10-3Lines changed: 10 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,28 +78,35 @@ Currently the 'stub' api for handling world state, and the 'Client Identity' is
78
78
Each contract has a 'createContext' method that can be overridden by specific implementations to provide specific control to add information to the
79
79
80
80
81
-
### Before, After and Unknown Functions
81
+
### Before, After, Around and Unknown Functions
82
82
83
83
The Contract class defines three functions that can be overridden by specific implementations.
84
84
85
85
```javascript
86
86
asyncbeforeTransaction(ctx) {
87
-
// default implementation is do nothing
87
+
// default implementation is do nothing
88
88
}
89
89
90
90
asyncafterTransaction(ctx, result) {
91
91
// default implementation is do nothing
92
92
}
93
+
94
+
asyncaroundTransaction(ctx, fn, parameters) {
95
+
// default implementation invokes `fn`
96
+
}
93
97
```
94
98
95
-
Before is called immediately before the transaction function, and after immediately afterwards. Note that before does not get the arguments to the function (note this was the subject of debate, opinions welcomed). After gets the result from the transaction function (this is the result returned from transaction function without any processing).
99
+
Before is called immediately before the transaction function, and after immediately afterwards. Note that before does not get the arguments to the function (note this was the subject of debate, opinions welcomed). After gets the result from the transaction function (this is the result returned from transaction function without any processing).
100
+
101
+
Around is the one responsible for invoking the trancaction function, and allows you to wrap all of them into a code block.
96
102
97
103
If the transaction function throws an Error then the whole transaction fails, likewise if the before or after throws an Error then the transaction fails. (note that if say before throws an error the transaction function is never called, nor the after. Similarly if transaction function throws an Error, after is not called. )
98
104
99
105
Typical use cases of these functions would be
100
106
101
107
- logging of the functions called
102
108
- checks of the identity of the caller
109
+
- wrap all functions into a try/catch
103
110
104
111
The unknown function is called if the requested function is not known; the default implementation is to throw an error. `You've asked to invoke a function that does not exist: {requested function}`
105
112
However you can implement an `unkownTransition` function - this can return a successful or throw an error as you wish.
0 commit comments