github.com/cheng762/platon-go@v1.8.17-0.20190529111256-7deff2d7be26/mpc/mpc_processor_off_linux.go (about) 1 // +build !mpcon 2 3 package mpc 4 5 /// test part 6 7 /* 8 #include <stdio.h> 9 #include <stdlib.h> 10 11 void notify_security_init(const char* icecfg, const char* url) { 12 printf("init : icecfg : %s, url : %s", icecfg, url); 13 } 14 15 void notify_security_calculation(const char* taskid, const char* pubkey, const char* address, const char* ir_address, const char* method, const char* extra) { 16 printf("Received Params: taskId:%s, pubkey:%s, addr:%s, irAddr:%s, method:%s, extra:%s", taskid, pubkey, address, ir_address, method, extra); 17 } 18 */ 19 import "C" 20 21 /* 22 #cgo LDFLAGS: -Wl,-rpath="./libs" 23 #cgo LDFLAGS: -L./libs 24 #cgo LDFLAGS: -lmpc_vm_platonsdk 25 #include <stdio.h> 26 #include <stdlib.h> 27 #include "platonvmsdk.h" 28 */ 29 //import "C" 30 31 import ( 32 "github.com/PlatONnetwork/PlatON-Go/common" 33 "github.com/PlatONnetwork/PlatON-Go/log" 34 "unsafe" 35 ) 36 37 type MPCParams struct { 38 TaskId string 39 Pubkey string 40 From common.Address 41 IRAddr common.Address 42 Method string 43 Extra string 44 } 45 46 func InitVM(icepath string, httpEndpoint string) { 47 cCfg := C.CString(icepath) 48 cUrl := C.CString(httpEndpoint) 49 defer func() { 50 C.free(unsafe.Pointer(cCfg)) 51 C.free(unsafe.Pointer(cUrl)) 52 }() 53 C.notify_security_init(cCfg, cUrl) 54 log.Info("Init mpc processor success", "osType", "linux", "icepath", icepath, "httpEndpoint", httpEndpoint) 55 } 56 57 func ExecuteMPCTxForRedis(params MPCParams) (err error) { 58 return nil 59 } 60 61 func ExecuteMPCTx(params MPCParams) error { 62 63 cTaskId := C.CString(params.TaskId) 64 cPubKey := C.CString(params.Pubkey) 65 cAddr := C.CString(params.From.Hex()) 66 cIRAddr := C.CString(params.IRAddr.Hex()) 67 cMethod := C.CString(params.Method) 68 cExtra := C.CString(params.Extra) 69 70 // call interface 71 C.notify_security_calculation(cTaskId, cPubKey, cAddr, cIRAddr, cMethod, cExtra) 72 73 defer func() { 74 // free memory 75 C.free(unsafe.Pointer(cTaskId)) 76 C.free(unsafe.Pointer(cPubKey)) 77 C.free(unsafe.Pointer(cAddr)) 78 C.free(unsafe.Pointer(cIRAddr)) 79 C.free(unsafe.Pointer(cMethod)) 80 C.free(unsafe.Pointer(cExtra)) 81 }() 82 83 log.Info("Notify mvm success, ExecuteMPCTx method invoke success.", 84 "taskId", params.TaskId, 85 "pubkey", params.Pubkey, 86 "from", params.From.Hex(), 87 "irAddr", params.IRAddr.Hex(), 88 "method", params.Method) 89 90 return nil 91 }