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

Function addAttributesByController

smartcontract/service/native/did/controller.go:233–274  ·  view source on GitHub ↗
(srvc *native.NativeService)

Source from the content-addressed store, hash-verified

231}
232
233func addAttributesByController(srvc *native.NativeService) ([]byte, error) {
234 source := common.NewZeroCopySource(srvc.Input)
235 // arg0: id
236 arg0, err := utils.DecodeVarBytes(source)
237 if err != nil {
238 return utils.BYTE_FALSE, fmt.Errorf("argument 0 error")
239 }
240
241 // arg1: attributes
242 num, err := utils.DecodeVarUint(source)
243 if err != nil {
244 return utils.BYTE_FALSE, fmt.Errorf("argument 1 error: %s", err)
245 }
246 var arg1 = make([]attribute, 0)
247 for i := 0; i < int(num); i++ {
248 var v attribute
249 err = v.Deserialization(source)
250 if err != nil {
251 return utils.BYTE_FALSE, fmt.Errorf("argument 1 error: %s", err)
252 }
253 arg1 = append(arg1, v)
254 }
255
256 encId, err := encodeID(arg0)
257 if err != nil {
258 return utils.BYTE_FALSE, err
259 }
260
261 err = verifyControllerSignature(srvc, encId, source)
262 if err != nil {
263 return utils.BYTE_FALSE, fmt.Errorf("verification failed, %s", err)
264 }
265
266 err = batchInsertAttr(srvc, encId, arg1)
267 if err != nil {
268 return utils.BYTE_FALSE, fmt.Errorf("insert attributes error, %s", err)
269 }
270
271 paths := getAttrKeys(arg1)
272 triggerAttributeEvent(srvc, "add", arg0, paths)
273 return utils.BYTE_TRUE, nil
274}
275
276func removeAttributeByController(srvc *native.NativeService) ([]byte, error) {
277 source := common.NewZeroCopySource(srvc.Input)

Callers 1

ctrlAddAttrFunction · 0.85

Calls 10

DeserializationMethod · 0.95
NewZeroCopySourceFunction · 0.92
DecodeVarBytesFunction · 0.92
DecodeVarUintFunction · 0.92
encodeIDFunction · 0.85
batchInsertAttrFunction · 0.85
getAttrKeysFunction · 0.85
triggerAttributeEventFunction · 0.85
ErrorfMethod · 0.80

Tested by 1

ctrlAddAttrFunction · 0.68