// NewUpdateTx is called on Channels which are in phase OPEN. It makes a new UpdateTx, // signs it, saves it as MyProposedUpdateTx, and sends it to the Counterparty. func (a *CallerAPI) NewUpdateTx(state []byte, channelID string, fast bool) error { var err error return a.DB.Update(func(tx *bolt.Tx) error { ch := &core.Channel{} ch, err = access.GetChannel(tx, channelID) if err != nil { return err } utx := ch.NewUpdateTx(state, fast) ev, err := core.SerializeUpdateTx(utx) if err != nil { return err } ch.SignProposedUpdateTx(ev, utx) err = a.CounterpartyClient.AddProposedUpdateTx(ev, ch.Counterparty.Address) if err != nil { return err } err = access.SetChannel(tx, ch) if err != nil { return err } return nil }) }
func Test(t *testing.T) { otx, err := c1_Account.NewOpeningTx("shibby", c1_Counterparty, []byte{166, 179}, 86400) if err != nil { t.Fatal(err) } ev, err := c.SerializeOpeningTx(otx) if err != nil { t.Fatal(err) } c1_Account.AppendSignature(ev) ch1, err := c.NewChannel(ev, otx, c1_Account, c1_Counterparty) if err != nil { t.Fatal(err) } // --- Send to second party --- err = c2_Account.CheckOpeningTx(ev, c2_Counterparty) if err != nil { t.Fatal(err) } ch2, err := c.NewChannel(ev, otx, c2_Account, c2_Counterparty) if err != nil { t.Fatal(err) } c2_Account.AppendSignature(ev) // --- Send to judge --- jch, err := j_judge.AddChannel(ev, otx, j_c1, j_c2) if err != nil { t.Fatal(err) } jch.Confirm() // --- Send back to accounts --- ch1.Open(jch.OpeningTxEnvelope, jch.OpeningTx) if err != nil { t.Fatal(err) } ch2.Open(jch.OpeningTxEnvelope, jch.OpeningTx) if err != nil { t.Fatal(err) } // --- Make update tx utx := ch1.NewUpdateTx([]byte{164, 179}, false) utxEv, err := c.SerializeUpdateTx(utx) if err != nil { t.Fatal(err) } ch1.SignProposedUpdateTx(utxEv, utx) // --- Send to second party --- fmt.Println(utxEv.Signatures[0]) err = ch2.AddProposedUpdateTx(utxEv, utx) if err != nil { t.Fatal(err) } ch2.CosignProposedUpdateTx() fmt.Println(utxEv.Signatures[1]) //, --- Make follow on tx ftx := ch2.NewFollowOnTx([]byte{0, 4}) ftxEv, err := c.SerializeFollowOnTx(ftx) if err != nil { t.Fatal(err) } ch2.AddFollowOnTx(ftxEv) // // --- Send to judge --- // err = jch.AddProposedUpdateTx(utxEv, utx) // if err != nil { // t.Fatal(err) // } // jch.Judge.AppendSignature(utxEv) // // --- Back to participants --- // _, err = ch1.AddFullUpdateTx(utxEv, utx) // if err != nil { // t.Fatal(err) // } // _, err = ch2.AddFullUpdateTx(utxEv, utx) // if err != nil { // t.Fatal(err) // } }