MCPcopy Create free account
hub / github.com/DNAProject/DNA / HandleInvokeTransaction

Method HandleInvokeTransaction

core/store/ledgerstore/tx_handler.go:82–129  ·  view source on GitHub ↗

HandleInvokeTransaction deal with smart contract invoke transaction

(store store.LedgerStore, overlay *overlaydb.OverlayDB, gasTable map[string]uint64, cache *storage.CacheDB,
	tx *types.Transaction, block *types.Block, notify *event.ExecuteNotify)

Source from the content-addressed store, hash-verified

80
81//HandleInvokeTransaction deal with smart contract invoke transaction
82func (self *StateStore) HandleInvokeTransaction(store store.LedgerStore, overlay *overlaydb.OverlayDB, gasTable map[string]uint64, cache *storage.CacheDB,
83 tx *types.Transaction, block *types.Block, notify *event.ExecuteNotify) error {
84 invoke := tx.Payload.(*payload.InvokeCode)
85
86 // init smart contract configuration info
87 config := &smartcontract.Config{
88 Time: block.Header.Timestamp,
89 Height: block.Header.Height,
90 Tx: tx,
91 BlockHash: block.Hash(),
92 }
93
94 var (
95 costGasLimit uint64
96 availableGasLimit uint64
97 err error
98 )
99
100 availableGasLimit = tx.GasLimit
101
102 //init smart contract info
103 sc := smartcontract.SmartContract{
104 Config: config,
105 CacheDB: cache,
106 Store: store,
107 GasTable: gasTable,
108 Gas: availableGasLimit,
109 WasmExecStep: sysconfig.DEFAULT_WASM_MAX_STEPCOUNT,
110 PreExec: false,
111 }
112
113 //start the smart contract executive function
114 engine, _ := sc.NewExecuteEngine(invoke.Code, tx.TxType)
115
116 _, err = engine.Invoke()
117 if err != nil {
118 return err
119 }
120 costGasLimit = availableGasLimit - sc.Gas
121
122 var notifies []*event.NotifyEventInfo
123 notify.Notify = append(notify.Notify, sc.Notifications...)
124 notify.Notify = append(notify.Notify, notifies...)
125 notify.GasConsumed = costGasLimit
126 notify.State = event.CONTRACT_STATE_SUCCESS
127 sc.CacheDB.Commit()
128 return nil
129}
130
131func SaveNotify(eventStore scommon.EventStore, txHash common.Uint256, notify *event.ExecuteNotify) error {
132 if !sysconfig.DefConfig.Common.EnableEventLog {

Callers 1

handleTransactionMethod · 0.80

Calls 4

NewExecuteEngineMethod · 0.95
CommitMethod · 0.80
HashMethod · 0.65
InvokeMethod · 0.65

Tested by

no test coverage detected