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

Method CreateUser

11_app_dev/chaincode_example05.go:44–71  ·  view source on GitHub ↗
(ctx contractapi.TransactionContextInterface, energy string, money string)

Source from the content-addressed store, hash-verified

42}
43
44func (s *SmartContract) CreateUser(ctx contractapi.TransactionContextInterface, energy string, money string) (*Home, error) {
45 energyValue, err := parseNonNegativeAmount(energy)
46 if err != nil {
47 return nil, err
48 }
49 moneyValue, err := parseNonNegativeAmount(money)
50 if err != nil {
51 return nil, err
52 }
53 id, err := nextID(ctx, homeCounterKey)
54 if err != nil {
55 return nil, err
56 }
57 address := newAddress(ctx, "home")
58 home := &Home{
59 Address: address,
60 Energy: energyValue,
61 Money: moneyValue,
62 ID: id,
63 Status: homeAvailableForTrade,
64 PriKey: address + "1",
65 PubKey: address + "2",
66 }
67 if err := putHome(ctx, home); err != nil {
68 return nil, err
69 }
70 return home, nil
71}
72
73func (s *SmartContract) BuyByAddress(ctx contractapi.TransactionContextInterface, sellerAddress string, buyerSignature string, buyerAddress string, energy string) (*EnergyTransaction, error) {
74 energyValue, err := parsePositiveAmount(energy)

Callers

nothing calls this directly

Calls 4

putHomeFunction · 0.85
parseNonNegativeAmountFunction · 0.70
nextIDFunction · 0.70
newAddressFunction · 0.70

Tested by

no test coverage detected