Пример #1
0
func ComposeChainSubmit(name string, data []byte) ([]byte, error) {
	type chainsubmit struct {
		ChainID     string
		ChainCommit json.RawMessage
		EntryReveal json.RawMessage
	}

	e := factom.NewEntry()
	if err := e.UnmarshalJSON(data); err != nil {
		return nil, err
	}
	c := factom.NewChain(e)

	sub := new(chainsubmit)
	we := factoidState.GetDB().GetRaw([]byte(fct.W_NAME), []byte(name))
	switch we.(type) {
	case wallet.IWalletEntry:
		pub := new([fct.ADDRESS_LENGTH]byte)
		copy(pub[:], we.(wallet.IWalletEntry).GetKey(0))
		pri := new([fct.PRIVATE_LENGTH]byte)
		copy(pri[:], we.(wallet.IWalletEntry).GetPrivKey(0))

		sub.ChainID = c.ChainID

		if j, err := factom.ComposeChainCommit(pub, pri, c); err != nil {
			return nil, err
		} else {
			sub.ChainCommit = j
		}

		if j, err := factom.ComposeEntryReveal(c.FirstEntry); err != nil {
			return nil, err
		} else {
			sub.EntryReveal = j
		}

	default:
		return nil, fmt.Errorf("Cannot use non Entry Credit Address for Chain Commit")
	}

	return json.Marshal(sub)
}
Пример #2
0
		ec, err := factom.FetchECAddress(ecpub)
		if err != nil {
			errorln(err)
			return
		}
		balance, err := factom.GetECBalance(ecpub)
		if err != nil {
			errorln(err)
			//return
		}
		if balance == 0 {
			errorln("Entry Credit balance is zero")
			//return
		}

		j, err := factom.ComposeChainCommit(c, ec)
		if err != nil {
			errorln(err)
			return
		}
		fmt.Println(j)

		j, err = factom.ComposeChainReveal(c)
		if err != nil {
			errorln(err)
			return
		}
		fmt.Println(j)
	}
	help.Add("composechain", cmd)
	return cmd