new.go 952 Bytes
Newer Older
Loïck Bonniot's avatar
Loïck Bonniot committed
1 2 3 4
package main

import (
	"fmt"
5
	"os"
Loïck Bonniot's avatar
Loïck Bonniot committed
6 7 8 9

	"dfss/dfssc/sign"
)

Loïck Bonniot's avatar
Loïck Bonniot committed
10
func newContract(_ []string) {
Loïck Bonniot's avatar
Loïck Bonniot committed
11 12 13
	fmt.Println("Creating a new contract")

	passphrase, filepath, comment, signers := getContractInfo()
14
	err := sign.SendNewContract(fca, fcert, fkey, addrPort, passphrase, filepath, comment, signers)
Loïck Bonniot's avatar
Loïck Bonniot committed
15
	if err != nil {
16 17
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
Loïck Bonniot's avatar
Loïck Bonniot committed
18 19 20 21 22 23
	}
}

// getContractInfo asks user for contract informations
func getContractInfo() (passphrase string, path string, comment string, signers []string) {

24 25
	signers = make([]string, 1)

Loïck Bonniot's avatar
Loïck Bonniot committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
	var signersBuf string
	_ = readPassword(&passphrase, false)
	readStringParam("Contract path", "", &path)
	readStringParam("Comment", "(no comment)", &comment)
	readStringParam("Signer 1", "mail@example.com", &signers[0])

	i := 2
	for {
		readStringParam(fmt.Sprintf("Signer %d (return to end)", i), "", &signersBuf)
		if len(signersBuf) == 0 {
			break
		}
		signers = append(signers, signersBuf)
		i++
	}
	return
}