MCPcopy Create free account
hub / github.com/DEROFDN/Engram / executeContractFunction

Function executeContractFunction

functions.go:3158–3251  ·  view source on GitHub ↗

Execute arbitrary exportable smart contract functions

(scid crypto.Hash, ringsize uint64, dero_amount uint64, asset_amount uint64, funcName string, params []dvm.Variable)

Source from the content-addressed store, hash-verified

3156
3157// Execute arbitrary exportable smart contract functions
3158func executeContractFunction(scid crypto.Hash, ringsize uint64, dero_amount uint64, asset_amount uint64, funcName string, params []dvm.Variable) (storage uint64, err error) {
3159 var args = rpc.Arguments{}
3160 var zero uint64
3161 var dest string
3162
3163 args = append(args, rpc.Argument{Name: "entrypoint", DataType: "S", Value: funcName})
3164 args = append(args, rpc.Argument{Name: "SC_ID", DataType: "H", Value: scid})
3165 args = append(args, rpc.Argument{Name: "SC_ACTION", DataType: "U", Value: uint64(rpc.SC_CALL)})
3166
3167 for p := range params {
3168 if params[p].Type == 0x4 {
3169 args = append(args, rpc.Argument{Name: params[p].Name, DataType: "U", Value: params[p].ValueUint64})
3170 } else {
3171 args = append(args, rpc.Argument{Name: params[p].Name, DataType: "S", Value: params[p].ValueString})
3172 }
3173 }
3174
3175 switch session.Network {
3176 case NETWORK_MAINNET:
3177 dest = "dero1qykyta6ntpd27nl0yq4xtzaf4ls6p5e9pqu0k2x4x3pqq5xavjsdxqgny8270"
3178 case NETWORK_SIMULATOR:
3179 dest = "deto1qyvyeyzrcm2fzf6kyq7egkes2ufgny5xn77y6typhfx9s7w3mvyd5qqynr5hx"
3180 default:
3181 dest = "deto1qy0ehnqjpr0wxqnknyc66du2fsxyktppkr8m8e6jvplp954klfjz2qqdzcd8p"
3182 }
3183
3184 var transfers []rpc.Transfer
3185
3186 if dero_amount != zero {
3187 burn := dero_amount
3188
3189 transfer := rpc.Transfer{
3190 Destination: dest,
3191 Amount: 0,
3192 Burn: burn,
3193 }
3194
3195 transfers = append(transfers, transfer)
3196 }
3197 if asset_amount != zero {
3198 burn := asset_amount
3199
3200 transfer := rpc.Transfer{
3201 SCID: scid,
3202 Destination: dest,
3203 Amount: 0,
3204 Burn: burn,
3205 }
3206
3207 transfers = append(transfers, transfer)
3208 }
3209
3210 if len(transfers) < 1 {
3211 transfer := rpc.Transfer{
3212 Destination: dest,
3213 Amount: 0,
3214 Burn: 0,
3215 }

Callers 1

layoutAssetManagerFunction · 0.85

Calls 1

getGasEstimateFunction · 0.85

Tested by

no test coverage detected