Exemplo n.º 1
0
func (a *CallerAPI) AddAccount(
	name string,
	judge []byte,
	pubkey []byte,
	address string,
) error {
	return a.DB.Update(func(tx *bolt.Tx) error {
		jd, err := access.GetJudge(tx, judge)
		if err != nil {
			return err
		}

		acct := &core.Account{
			Name:    name,
			Judge:   jd,
			Pubkey:  pubkey,
			Address: address,
		}

		err = access.SetAccount(tx, acct)
		if err != nil {
			return err
		}

		return nil
	})
}
Exemplo n.º 2
0
func (a *PeerAPI) AddChannel(ev *wire.Envelope) error {
	var err error
	err = a.DB.Update(func(tx *bolt.Tx) error {

		otx := &wire.OpeningTx{}
		err = proto.Unmarshal(ev.Payload, otx)
		if err != nil {
			return err
		}

		_, nilErr := access.GetChannel(tx, otx.ChannelId)
		if nilErr == nil {
			return errors.New("channel already exists")
		}
		_, ok := nilErr.(*access.NilError)
		if !ok {
			return err
		}

		acct0, err := access.GetAccount(tx, otx.Pubkeys[0])
		if err != nil {
			return err
		}

		acct1, err := access.GetAccount(tx, otx.Pubkeys[1])
		if err != nil {
			return err
		}

		judge, err := access.GetJudge(tx, acct0.Judge.Pubkey)
		if err != nil {
			return err
		}

		ch, err := judge.AddChannel(ev, otx, acct0, acct1)

		access.SetChannel(tx, ch)
		if err != nil {
			return err
		}

		return nil
	})
	if err != nil {
		return err
	}

	return nil
}