func testSNativeCALL(t *testing.T, expectPass bool, blockCache *BlockCache, doug *acm.Account, snativeAddress, data []byte, f func([]byte) error) { if expectPass { perm, err := ptypes.PermStringToFlag(TrimmedString(snativeAddress)) if err != nil { t.Fatal(err) } doug.Permissions.Base.Set(perm, true) } var addr []byte contractCode := callContractCode(snativeAddress) doug.Code = contractCode blockCache.UpdateAccount(doug) addr = doug.Address tx, _ := types.NewCallTx(blockCache, user[0].PubKey, addr, data, 100, 10000, 100) tx.Sign(chainID, user[0]) fmt.Println("subscribing to", types.EventStringAccCall(snativeAddress)) ev, exception := execTxWaitEvent(t, blockCache, tx, types.EventStringAccCall(snativeAddress)) if exception == ExceptionTimeOut { t.Fatal("Timed out waiting for event") } if expectPass { if exception != "" { t.Fatal("Unexpected exception", exception) } evv := ev.(types.EventDataCall) ret := evv.Return if err := f(ret); err != nil { t.Fatal(err) } } else { if exception == "" { t.Fatal("Expected exception") } } }
func decodeAddressPermFlag(addrS, permFlagS string) (addr []byte, pFlag ptypes.PermFlag, err error) { if addr, err = hex.DecodeString(addrS); err != nil { return } if pFlag, err = ptypes.PermStringToFlag(permFlagS); err != nil { return } return }
func cliStringsToInts(cmd *cobra.Command, args []string) { cmd.ParseFlags(args) if len(args) == 0 { Exit(fmt.Errorf("Please enter at least one `<permission>:<value>` pair like `send:0 call:1 create_account:1`")) } bp := types.ZeroBasePermissions for _, a := range args { spl := strings.Split(a, ":") if len(spl) != 2 { Exit(fmt.Errorf("arguments must be like `send:1`, not %s", a)) } name, v := spl[0], spl[1] vi := v[0] - '0' pf, err := types.PermStringToFlag(name) IfExit(err) bp.Set(pf, vi > 0) } printPerms(bp, BitmaskFlag) }
func Permissions(nodeAddr, pubkey, addrS, nonceS, permFunc string, argsS []string) (*types.PermissionsTx, error) { pub, _, _, nonce, err := checkCommon(nodeAddr, pubkey, addrS, "0", "0") if err != nil { return nil, err } var args ptypes.PermArgs switch permFunc { case "set_base": addr, pF, err := decodeAddressPermFlag(argsS[0], argsS[1]) if err != nil { return nil, err } if len(argsS) != 3 { return nil, fmt.Errorf("set_base also takes a value (true or false)") } var value bool if argsS[2] == "true" { value = true } else if argsS[2] == "false" { value = false } else { return nil, fmt.Errorf("Unknown value %s", argsS[2]) } args = &ptypes.SetBaseArgs{addr, pF, value} case "unset_base": addr, pF, err := decodeAddressPermFlag(argsS[0], argsS[1]) if err != nil { return nil, err } args = &ptypes.UnsetBaseArgs{addr, pF} case "set_global": pF, err := ptypes.PermStringToFlag(argsS[0]) if err != nil { return nil, err } var value bool if argsS[1] == "true" { value = true } else if argsS[1] == "false" { value = false } else { return nil, fmt.Errorf("Unknown value %s", argsS[1]) } args = &ptypes.SetGlobalArgs{pF, value} case "add_role": addr, err := hex.DecodeString(argsS[0]) if err != nil { return nil, err } args = &ptypes.AddRoleArgs{addr, argsS[1]} case "rm_role": addr, err := hex.DecodeString(argsS[0]) if err != nil { return nil, err } args = &ptypes.RmRoleArgs{addr, argsS[1]} default: return nil, fmt.Errorf("Invalid permission function for use in PermissionsTx: %s", permFunc) } // args := snativeArgs( tx := types.NewPermissionsTxWithNonce(pub, args, int(nonce)) return tx, nil }