MCPcopy
hub / github.com/yeasy/blockchain_guide / recordTransaction

Function recordTransaction

11_app_dev/chaincode_example03.go:317–332  ·  view source on GitHub ↗
(ctx contractapi.TransactionContextInterface, fromType int, fromID int, toType int, toID int, amount int)

Source from the content-addressed store, hash-verified

315}
316
317func recordTransaction(ctx contractapi.TransactionContextInterface, fromType int, fromID int, toType int, toID int, amount int) (*Transaction, error) {
318 id, err := nextID(ctx, transferCounterKey)
319 if err != nil {
320 return nil, err
321 }
322 timestamp, err := ctx.GetStub().GetTxTimestamp()
323 if err != nil {
324 return nil, fmt.Errorf("failed to read transaction timestamp: %w", err)
325 }
326
327 transaction := &Transaction{ID: id, FromType: fromType, FromID: fromID, ToType: toType, ToID: toID, Time: timestamp.Seconds, Number: amount}
328 if err := putJSON(ctx, transactionKey(id), transaction); err != nil {
329 return nil, err
330 }
331 return transaction, nil
332}
333
334func readCenterBank(ctx contractapi.TransactionContextInterface) (*CenterBank, error) {
335 var centerBank CenterBank

Callers 4

IssueCoinMethod · 0.85
IssueCoinToBankMethod · 0.85
IssueCoinToCompanyMethod · 0.85
TransferMethod · 0.85

Calls 3

transactionKeyFunction · 0.85
nextIDFunction · 0.70
putJSONFunction · 0.70

Tested by

no test coverage detected