OSDN Git Service

add multisig contract template (#1095)
authoroysheng <33340252+oysheng@users.noreply.github.com>
Wed, 27 Jun 2018 06:41:45 +0000 (14:41 +0800)
committerPaladz <yzhu101@uottawa.ca>
Wed, 27 Jun 2018 06:41:45 +0000 (14:41 +0800)
cmd/bytomcli/commands/template.go
cmd/bytomcli/commands/transaction.go

index 3af595f..93bc5ed 100644 (file)
@@ -14,3 +14,20 @@ var buildLockWithPublicKeyReqFmtByAlias = `
                {"type": "control_program", "asset_alias": "%s", "amount": %s, "control_program": "%s"},
                {"type": "spend_account", "asset_alias": "BTM", "amount": %s, "account_alias": "%s"}
        ]}`
+
+// contract is LockWithMultiSig
+var buildLockWithMultiSigReqFmt = `
+       {"actions": [
+               {"type": "spend_account_unspent_output", "output_id": "%s", "arguments": [{"type": "raw_tx_signature", "raw_data": {"derivation_path": ["%s", "%s"], "xpub": "%s"}},
+                               {"type": "raw_tx_signature", "raw_data": {"derivation_path": ["%s", "%s"], "xpub": "%s"}}]},
+               {"type": "control_program", "asset_id": "%s", "amount": %s, "control_program": "%s"},
+               {"type": "spend_account", "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "amount": %s, "account_id": "%s"}
+       ]}`
+
+var buildLockWithMultiSigReqFmtByAlias = `
+       {"actions": [
+               {"type": "spend_account_unspent_output", "output_id": "%s", "arguments": [{"type": "raw_tx_signature", "raw_data": {"derivation_path": ["%s", "%s"], "xpub": "%s"}},
+                               {"type": "raw_tx_signature", "raw_data": {"derivation_path": ["%s", "%s"], "xpub": "%s"}}]},
+               {"type": "control_program", "asset_alias": "%s", "amount": %s, "control_program": "%s"},
+               {"type": "spend_account", "asset_alias": "BTM", "amount": %s, "account_alias": "%s"}
+       ]}`
index 9c306c8..1ac5a24 100644 (file)
@@ -176,7 +176,7 @@ var buildTransactionCmd = &cobra.Command{
                        switch contractName {
                        case "LockWithPublicKey":
                                if len(args) != 7 {
-                                       fmt.Println("%s <rootPub> <path1> <path2> [flags]\n", usage)
+                                       fmt.Printf("%s <rootPub> <path1> <path2> [flags]\n\n", usage)
                                        os.Exit(util.ErrLocalExe)
                                }
 
@@ -191,6 +191,25 @@ var buildTransactionCmd = &cobra.Command{
                                }
                                buildReqStr = fmt.Sprintf(buildLockWithPublicKeyReqFmt, outputID, path1, path2, rootPub, assetInfo, amount, program, btmGas, accountInfo)
 
+                       case "LockWithMultiSig":
+                               if len(args) != 10 {
+                                       fmt.Printf("%s <rootPub1> <path11> <path12> <rootPub2> <path21> <path22> [flags]\n\n", usage)
+                                       os.Exit(util.ErrLocalExe)
+                               }
+
+                               outputID := args[3]
+                               rootPub1 := args[4]
+                               path11 := args[5]
+                               path12 := args[6]
+                               rootPub2 := args[7]
+                               path21 := args[8]
+                               path22 := args[9]
+                               if alias {
+                                       buildReqStr = fmt.Sprintf(buildLockWithMultiSigReqFmtByAlias, outputID, path11, path12, rootPub1, path21, path22, rootPub2, assetInfo, amount, program, btmGas, accountInfo)
+                                       break
+                               }
+                               buildReqStr = fmt.Sprintf(buildLockWithMultiSigReqFmt, outputID, path11, path12, rootPub1, path21, path22, rootPub2, assetInfo, amount, program, btmGas, accountInfo)
+
                        default:
                                jww.ERROR.Println("Invalid Contract template")
                                os.Exit(util.ErrLocalExe)