• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: Commit

Golang implemented sidechain for Bytom


Commit MetaInfo

Revisiond3c2fdb23869a73a3b6ea0b6ae683061aa96fcf2 (tree)
Time2019-07-04 16:14:39
AuthorHAOYUatHZ <haoyu@prot...>
CommiterHAOYUatHZ

Log Message

Merge remote-tracking branch 'origin/master' into blockheight

Change Summary

Incremental Difference

--- a/accesstoken/accesstoken.go
+++ b/accesstoken/accesstoken.go
@@ -72,7 +72,6 @@ func (cs *CredentialStore) Create(id, typ string) (*Token, error) {
7272
7373 hashedSecret := make([]byte, tokenSize)
7474 sha3pool.Sum256(hashedSecret, secret)
75-
7675 token := &Token{
7776 ID: id,
7877 Token: fmt.Sprintf("%s:%x", id, hashedSecret),
@@ -84,8 +83,8 @@ func (cs *CredentialStore) Create(id, typ string) (*Token, error) {
8483 if err != nil {
8584 return nil, err
8685 }
87- cs.DB.Set(key, value)
8886
87+ cs.DB.Set(key, value)
8988 return token, nil
9089 }
9190
@@ -95,12 +94,12 @@ func (cs *CredentialStore) Check(id string, secret string) error {
9594 return errors.WithDetailf(ErrBadID, "invalid id %q", id)
9695 }
9796
98- var value []byte
99- token := &Token{}
100-
101- if value = cs.DB.Get([]byte(id)); value == nil {
97+ value := cs.DB.Get([]byte(id))
98+ if value == nil {
10299 return errors.WithDetailf(ErrNoMatchID, "check id %q nonexisting", id)
103100 }
101+
102+ token := &Token{}
104103 if err := json.Unmarshal(value, token); err != nil {
105104 return err
106105 }
--- a/accesstoken/accesstoken_test.go
+++ b/accesstoken/accesstoken_test.go
@@ -1,7 +1,6 @@
11 package accesstoken
22
33 import (
4- "context"
54 "os"
65 "strings"
76 "testing"
@@ -27,23 +26,21 @@ func TestCreate(t *testing.T) {
2726 }
2827
2928 for _, c := range cases {
30- _, err := cs.Create(c.id, c.typ)
31- if errors.Root(err) != c.want {
29+ if _, err := cs.Create(c.id, c.typ); errors.Root(err) != c.want {
3230 t.Errorf("Create(%s, %s) error = %s want %s", c.id, c.typ, err, c.want)
3331 }
3432 }
3533 }
3634
3735 func TestList(t *testing.T) {
38- ctx := context.Background()
3936 testDB := dbm.NewDB("testdb", "leveldb", "temp")
4037 defer os.RemoveAll("temp")
41- cs := NewStore(testDB)
4238
39+ cs := NewStore(testDB)
4340 tokenMap := make(map[string]*Token)
44- tokenMap["ab"] = mustCreateToken(ctx, t, cs, "ab", "test")
45- tokenMap["bc"] = mustCreateToken(ctx, t, cs, "bc", "test")
46- tokenMap["cd"] = mustCreateToken(ctx, t, cs, "cd", "test")
41+ tokenMap["ab"] = mustCreateToken(t, cs, "ab", "test")
42+ tokenMap["bc"] = mustCreateToken(t, cs, "bc", "test")
43+ tokenMap["cd"] = mustCreateToken(t, cs, "cd", "test")
4744
4845 got, err := cs.List()
4946 if err != nil {
@@ -53,6 +50,7 @@ func TestList(t *testing.T) {
5350 if len(got) != len(tokenMap) {
5451 t.Error("List errored: get invalid length")
5552 }
53+
5654 for _, v := range got {
5755 if v.Token != tokenMap[v.ID].Token {
5856 t.Errorf("List error: ID: %s, expected token: %s, DB token: %s", v.ID, *tokenMap[v.ID], v.Token)
@@ -62,12 +60,11 @@ func TestList(t *testing.T) {
6260 }
6361
6462 func TestCheck(t *testing.T) {
65- ctx := context.Background()
6663 testDB := dbm.NewDB("testdb", "leveldb", "temp")
6764 defer os.RemoveAll("temp")
6865 cs := NewStore(testDB)
6966
70- token := mustCreateToken(ctx, t, cs, "x", "client")
67+ token := mustCreateToken(t, cs, "x", "client")
7168 tokenParts := strings.Split(token.Token, ":")
7269
7370 if err := cs.Check(tokenParts[0], tokenParts[1]); err != nil {
@@ -80,13 +77,12 @@ func TestCheck(t *testing.T) {
8077 }
8178
8279 func TestDelete(t *testing.T) {
83- ctx := context.Background()
8480 testDB := dbm.NewDB("testdb", "leveldb", "temp")
8581 defer os.RemoveAll("temp")
8682 cs := NewStore(testDB)
8783
8884 const id = "Y"
89- mustCreateToken(ctx, t, cs, id, "client")
85+ mustCreateToken(t, cs, id, "client")
9086
9187 err := cs.Delete(id)
9288 if err != nil {
@@ -104,13 +100,12 @@ func TestDeleteWithInvalidId(t *testing.T) {
104100 defer os.RemoveAll("temp")
105101 cs := NewStore(testDB)
106102
107- err := cs.Delete("@")
108- if errors.Root(err) != ErrBadID {
103+ if err := cs.Delete("@"); errors.Root(err) != ErrBadID {
109104 t.Errorf("Deletion with invalid id success, while it should not")
110105 }
111106 }
112107
113-func mustCreateToken(ctx context.Context, t *testing.T, cs *CredentialStore, id, typ string) *Token {
108+func mustCreateToken(t *testing.T, cs *CredentialStore, id, typ string) *Token {
114109 token, err := cs.Create(id, typ)
115110 if err != nil {
116111 t.Fatal(err)
--- a/account/accounts_test.go
+++ b/account/accounts_test.go
@@ -61,7 +61,7 @@ func TestCreateAccount(t *testing.T) {
6161 m := mockAccountManager(t)
6262 account, err := m.Create([]chainkd.XPub{testutil.TestXPub}, 1, "test-alias", signers.BIP0044)
6363 if err != nil {
64- testutil.FatalErr(t, err)
64+ t.Fatal(err)
6565 }
6666
6767 found, err := m.FindByID(account.ID)
@@ -121,12 +121,12 @@ func TestDeleteAccount(t *testing.T) {
121121
122122 account1, err := m.Create([]chainkd.XPub{testutil.TestXPub}, 1, "test-alias1", signers.BIP0044)
123123 if err != nil {
124- testutil.FatalErr(t, err)
124+ t.Fatal(err)
125125 }
126126
127127 account2, err := m.Create([]chainkd.XPub{testutil.TestXPub}, 1, "test-alias2", signers.BIP0044)
128128 if err != nil {
129- testutil.FatalErr(t, err)
129+ t.Fatal(err)
130130 }
131131
132132 found, err := m.FindByID(account1.ID)
@@ -135,7 +135,7 @@ func TestDeleteAccount(t *testing.T) {
135135 }
136136
137137 if err = m.DeleteAccount(account2.ID); err != nil {
138- testutil.FatalErr(t, err)
138+ t.Fatal(err)
139139 }
140140
141141 found, err = m.FindByID(account2.ID)
@@ -150,7 +150,7 @@ func TestFindByID(t *testing.T) {
150150
151151 found, err := m.FindByID(account.ID)
152152 if err != nil {
153- testutil.FatalErr(t, err)
153+ t.Fatal(err)
154154 }
155155
156156 if !testutil.DeepEqual(account, found) {
@@ -164,7 +164,7 @@ func TestFindByAlias(t *testing.T) {
164164
165165 found, err := m.FindByAlias("some-alias")
166166 if err != nil {
167- testutil.FatalErr(t, err)
167+ t.Fatal(err)
168168 }
169169
170170 if !testutil.DeepEqual(account, found) {
@@ -228,7 +228,7 @@ func mockAccountManager(t *testing.T) *Manager {
228228 func (m *Manager) createTestAccount(t testing.TB, alias string, tags map[string]interface{}) *Account {
229229 account, err := m.Create([]chainkd.XPub{testutil.TestXPub}, 1, alias, signers.BIP0044)
230230 if err != nil {
231- testutil.FatalErr(t, err)
231+ t.Fatal(err)
232232 }
233233
234234 return account
--- a/blockchain/txbuilder/txbuilder_test.go
+++ b/blockchain/txbuilder/txbuilder_test.go
@@ -59,7 +59,7 @@ func TestBuildIntra(t *testing.T) {
5959 expiryTime := time.Now().Add(time.Minute)
6060 got, err := Build(ctx, nil, actions, expiryTime, 0)
6161 if err != nil {
62- testutil.FatalErr(t, err)
62+ t.Fatal(err)
6363 }
6464
6565 want := &Template{
@@ -115,7 +115,7 @@ func TestBuildCrossOut(t *testing.T) {
115115 expiryTime := time.Now().Add(time.Minute)
116116 got, err := Build(ctx, nil, actions, expiryTime, 0)
117117 if err != nil {
118- testutil.FatalErr(t, err)
118+ t.Fatal(err)
119119 }
120120
121121 want := &Template{
--- a/common/bit_map.go
+++ /dev/null
@@ -1,53 +0,0 @@
1-package common
2-
3-import (
4- "errors"
5-)
6-
7-const bitLen = 32
8-
9-var (
10- errIndexOutOfBounds = errors.New("index out of bounds error")
11-)
12-
13-type BitMap struct {
14- size uint32
15- arr []int32
16-}
17-
18-func NewBitMap(size uint32) *BitMap {
19- obj := &BitMap{size: size}
20- num := (size + bitLen - 1) / bitLen
21- arr := make([]int32, num)
22- obj.arr = arr
23- return obj
24-}
25-
26-func (b *BitMap) Set(index uint32) error {
27- if index >= b.size {
28- return errIndexOutOfBounds
29- }
30-
31- arrIndex, bitIndex := index / bitLen, index % bitLen
32- b.arr[arrIndex] |= (1 << bitIndex)
33- return nil
34-}
35-
36-func (b *BitMap) Clean(index uint32) error {
37- if index >= b.size {
38- return errIndexOutOfBounds
39- }
40-
41- arrIndex, bitIndex := index / bitLen, index % bitLen
42- b.arr[arrIndex] &= (^(1 << bitIndex))
43- return nil
44-}
45-
46-func (b *BitMap) Test(index uint32) (bool, error) {
47- if index >= b.size {
48- return false, errIndexOutOfBounds
49- }
50-
51- arrIndex, bitIndex := index / bitLen, index % bitLen
52- return b.arr[arrIndex] & (1 << bitIndex) != 0, nil
53-}
--- a/protocol/bc/bc.pb.go
+++ b/protocol/bc/bc.pb.go
@@ -693,12 +693,11 @@ func (m *Spend) GetOrdinal() uint64 {
693693
694694 type CrossChainInput struct {
695695 MainchainOutputId *Hash `protobuf:"bytes,1,opt,name=mainchain_output_id,json=mainchainOutputId" json:"mainchain_output_id,omitempty"`
696- Value *AssetAmount `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
697- WitnessDestination *ValueDestination `protobuf:"bytes,3,opt,name=witness_destination,json=witnessDestination" json:"witness_destination,omitempty"`
698- ControlProgram *Program `protobuf:"bytes,4,opt,name=control_program,json=controlProgram" json:"control_program,omitempty"`
699- AssetDefinition *AssetDefinition `protobuf:"bytes,5,opt,name=asset_definition,json=assetDefinition" json:"asset_definition,omitempty"`
700- WitnessArguments [][]byte `protobuf:"bytes,6,rep,name=witness_arguments,json=witnessArguments,proto3" json:"witness_arguments,omitempty"`
701- Ordinal uint64 `protobuf:"varint,7,opt,name=ordinal" json:"ordinal,omitempty"`
696+ WitnessDestination *ValueDestination `protobuf:"bytes,2,opt,name=witness_destination,json=witnessDestination" json:"witness_destination,omitempty"`
697+ ControlProgram *Program `protobuf:"bytes,3,opt,name=control_program,json=controlProgram" json:"control_program,omitempty"`
698+ AssetDefinition *AssetDefinition `protobuf:"bytes,4,opt,name=asset_definition,json=assetDefinition" json:"asset_definition,omitempty"`
699+ WitnessArguments [][]byte `protobuf:"bytes,5,rep,name=witness_arguments,json=witnessArguments,proto3" json:"witness_arguments,omitempty"`
700+ Ordinal uint64 `protobuf:"varint,6,opt,name=ordinal" json:"ordinal,omitempty"`
702701 }
703702
704703 func (m *CrossChainInput) Reset() { *m = CrossChainInput{} }
@@ -713,13 +712,6 @@ func (m *CrossChainInput) GetMainchainOutputId() *Hash {
713712 return nil
714713 }
715714
716-func (m *CrossChainInput) GetValue() *AssetAmount {
717- if m != nil {
718- return m.Value
719- }
720- return nil
721-}
722-
723715 func (m *CrossChainInput) GetWitnessDestination() *ValueDestination {
724716 if m != nil {
725717 return m.WitnessDestination
@@ -781,65 +773,65 @@ func init() {
781773 func init() { proto.RegisterFile("bc.proto", fileDescriptor0) }
782774
783775 var fileDescriptor0 = []byte{
784- // 960 bytes of a gzipped FileDescriptorProto
785- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x56, 0x4d, 0x6f, 0x1b, 0x37,
786- 0x13, 0x86, 0x56, 0x6b, 0x49, 0x1e, 0x39, 0x96, 0x44, 0x27, 0xef, 0xbb, 0x08, 0x52, 0xd4, 0x58,
787- 0x20, 0x75, 0x8a, 0x02, 0x86, 0x3f, 0xd2, 0x8f, 0x43, 0x51, 0xd4, 0xb5, 0x9b, 0x46, 0x87, 0x20,
788- 0x05, 0x6d, 0xe8, 0xba, 0xa0, 0x76, 0x29, 0x89, 0xa8, 0xb4, 0x54, 0x49, 0xae, 0xea, 0xf8, 0x2f,
789- 0xf4, 0xdc, 0x43, 0x7f, 0x51, 0x0f, 0x45, 0xff, 0x4e, 0xaf, 0x2d, 0x38, 0xcb, 0x95, 0x56, 0x1f,
790- 0xb6, 0x13, 0x14, 0x45, 0xdb, 0xdb, 0xce, 0x70, 0xf8, 0xcc, 0x33, 0x0f, 0x67, 0xb8, 0x84, 0x46,
791- 0x3f, 0x3e, 0x9c, 0x2a, 0x69, 0x24, 0xf1, 0xfa, 0x71, 0xf8, 0x02, 0xfc, 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 0xca, 0x4c,
803- 0xc5, 0x9c, 0x3c, 0x86, 0xaa, 0xe2, 0x03, 0x87, 0xbb, 0x88, 0xb5, 0x4e, 0xf2, 0x14, 0xb6, 0x66,
804- 0x36, 0xd4, 0x21, 0xb5, 0xe6, 0x05, 0xe5, 0x35, 0xd3, 0x7c, 0x95, 0x3c, 0x86, 0xc6, 0x54, 0x6a,
805- 0xe4, 0x8c, 0x7a, 0xf9, 0x74, 0x6e, 0x87, 0xdf, 0x43, 0x1b, 0xb3, 0x5d, 0x70, 0x6d, 0x44, 0xca,
806- 0xb0, 0xae, 0xbf, 0x39, 0xe5, 0x1f, 0x1e, 0x34, 0xbf, 0x1a, 0xcb, 0xf8, 0xbb, 0x97, 0x9c, 0x25,
807- 0x5c, 0x91, 0x00, 0xea, 0xcb, 0x3d, 0x52, 0x98, 0xf6, 0x2c, 0x46, 0x5c, 0x0c, 0x47, 0xf3, 0xb3,
808- 0xc8, 0x2d, 0xf2, 0x1c, 0x3a, 0x53, 0xc5, 0x67, 0x42, 0x66, 0x3a, 0xea, 0x5b, 0x24, 0x7b, 0xa8,
809- 0xd5, 0x15, 0xba, 0xad, 0x22, 0x04, 0x73, 0x75, 0x13, 0xf2, 0x04, 0xb6, 0x8d, 0x98, 0x70, 0x6d,
810- 0xd8, 0x64, 0x8a, 0x7d, 0xe2, 0xd3, 0x85, 0x83, 0x7c, 0x0c, 0x1d, 0xa3, 0x58, 0xaa, 0x59, 0x6c,
811- 0x49, 0xea, 0x48, 0x49, 0x69, 0x82, 0xad, 0x15, 0xcc, 0x76, 0x39, 0x84, 0x4a, 0x69, 0xc8, 0x97,
812- 0xf0, 0xff, 0x92, 0x2f, 0xd2, 0x86, 0x99, 0x4c, 0x47, 0x23, 0xa6, 0x47, 0x41, 0x6d, 0x65, 0xf3,
813- 0xa3, 0x52, 0xe0, 0x25, 0xc6, 0xe1, 0xc0, 0x5d, 0x00, 0x59, 0x47, 0x08, 0xea, 0xb8, 0xf9, 0x91,
814- 0xd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f2, 0x14, 0xea, 0xc5, 0xad, 0xe0, 0xad, 0xdf, 0x0a, 0xc5, 0x1a, 0xf9, 0x06, 0x1e,
826- 0x16, 0x27, 0x97, 0x2c, 0x86, 0x50, 0x07, 0x55, 0x84, 0x7f, 0x38, 0x87, 0x2f, 0x4d, 0x28, 0xdd,
827- 0x73, 0x3b, 0x4a, 0xbe, 0x5b, 0x5a, 0xc0, 0xbf, 0xa5, 0x05, 0x24, 0x34, 0xce, 0xa5, 0x48, 0xfb,
828- 0x4c, 0x73, 0xf2, 0x35, 0xec, 0x6d, 0x60, 0xe0, 0xe6, 0x7f, 0x33, 0x01, 0xb2, 0x4e, 0xc0, 0xce,
829- 0x17, 0x53, 0x7d, 0x61, 0x14, 0x53, 0x6f, 0xdc, 0xa5, 0xbe, 0x70, 0x84, 0x3f, 0x56, 0xa0, 0xdd,
830- 0x4d, 0x8d, 0x62, 0xe7, 0x23, 0x26, 0xd2, 0xd7, 0x99, 0x99, 0x66, 0x86, 0x1c, 0x40, 0x2d, 0x57,
831- 0xcb, 0x25, 0x5b, 0x13, 0xd3, 0x2d, 0x93, 0xe7, 0xd0, 0x8a, 0x65, 0x6a, 0x94, 0x1c, 0x47, 0x77,
832- 0x68, 0xba, 0xeb, 0x62, 0x8a, 0x8b, 0x36, 0x80, 0xba, 0x54, 0x89, 0x48, 0xd9, 0xd8, 0x35, 0x65,
833- 0x61, 0x22, 0x9b, 0x73, 0x25, 0xb5, 0xfe, 0x57, 0xb0, 0xf9, 0xb9, 0x02, 0xd0, 0x93, 0x86, 0xff,
834- 0xc3, 0x3c, 0xec, 0x1f, 0x79, 0x26, 0x0d, 0xc7, 0xcb, 0x71, 0x87, 0xe2, 0x77, 0xf8, 0x6b, 0x05,
835- 0xb6, 0x7b, 0xdc, 0xc8, 0x6e, 0x6a, 0xa9, 0x1d, 0x41, 0x4b, 0x4f, 0x79, 0x6a, 0x22, 0x89, 0x54,
836- 0x17, 0x3f, 0xd3, 0xc5, 0x3c, 0x3f, 0xc0, 0x80, 0xbc, 0x94, 0x6e, 0x72, 0x5b, 0x73, 0x79, 0xef,
837- 0xd8, 0x5c, 0x1b, 0x9b, 0xbb, 0xba, 0xb9, 0xb9, 0xcb, 0x15, 0xfa, 0xcb, 0x4a, 0xbf, 0x06, 0xa0,
838- 0xdc, 0x08, 0xc5, 0x6d, 0xe0, 0xdb, 0x0b, 0x5d, 0x02, 0xf4, 0x96, 0x01, 0x7f, 0xa9, 0xc0, 0xd6,
839- 0xe5, 0x94, 0xa7, 0xc9, 0x7f, 0x5e, 0x9a, 0xdf, 0x3d, 0x68, 0x2d, 0x46, 0x22, 0x3f, 0xee, 0xcf,
840- 0x60, 0x6f, 0xc2, 0x44, 0x1a, 0x5b, 0xcf, 0x1d, 0x75, 0x75, 0xe6, 0x41, 0xf3, 0xda, 0xde, 0xf2,
841- 0x9d, 0x70, 0x8b, 0x04, 0xd5, 0x77, 0x94, 0x60, 0xc3, 0x20, 0xf8, 0xf7, 0x0f, 0xc2, 0x17, 0xd0,
842- 0xce, 0x9f, 0x84, 0xc9, 0xfc, 0x4d, 0xe7, 0xfe, 0xf8, 0x7b, 0x73, 0xba, 0x8b, 0xe7, 0x1e, 0x6d,
843- 0xb1, 0x95, 0xf7, 0xdf, 0x46, 0xe1, 0x6b, 0xf7, 0x0b, 0x5f, 0x5f, 0x12, 0xbe, 0x5f, 0xc3, 0x47,
844- 0xf8, 0xe9, 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x2b, 0x1b, 0x9e, 0x47, 0x90, 0x0b, 0x00, 0x00,
776+ // 951 bytes of a gzipped FileDescriptorProto
777+ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x56, 0x5f, 0x6f, 0x23, 0x35,
778+ 0x10, 0x57, 0x36, 0xdb, 0x24, 0x9d, 0xf4, 0x9a, 0xc4, 0xbd, 0x83, 0xd5, 0xe9, 0x10, 0xd5, 0x4a,
779+ 0x47, 0x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 0x2b, 0x8b, 0x77, 0x1c, 0x6d, 0xb1, 0x95, 0x87, 0xdd, 0x46, 0x45, 0xb7, 0xee, 0x57,
835+ 0xb4, 0xb6, 0xa4, 0x68, 0xbf, 0x86, 0xaf, 0xeb, 0xd3, 0xdf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x20,
836+ 0xd9, 0x30, 0x59, 0x69, 0x0b, 0x00, 0x00,
845837 }
--- a/protocol/bc/bc.proto
+++ b/protocol/bc/bc.proto
@@ -127,10 +127,9 @@ message Spend {
127127
128128 message CrossChainInput {
129129 Hash mainchain_output_id = 1;
130- AssetAmount value = 2;
131- ValueDestination witness_destination = 3;
132- Program control_program = 4;
133- AssetDefinition asset_definition = 5;
134- repeated bytes witness_arguments = 6;
135- uint64 ordinal = 7;
130+ ValueDestination witness_destination = 2;
131+ Program control_program = 3;
132+ AssetDefinition asset_definition = 4;
133+ repeated bytes witness_arguments = 5;
134+ uint64 ordinal = 6;
136135 }
--- a/protocol/bc/crosschain_input.go
+++ b/protocol/bc/crosschain_input.go
@@ -9,7 +9,6 @@ func (CrossChainInput) typ() string { return "crosschaininput1" }
99
1010 func (cci *CrossChainInput) writeForHash(w io.Writer) {
1111 mustWriteForHash(w, cci.MainchainOutputId)
12- mustWriteForHash(w, cci.Value)
1312 mustWriteForHash(w, cci.AssetDefinition)
1413 }
1514
@@ -23,10 +22,9 @@ func (cci *CrossChainInput) SetDestination(id *Hash, val *AssetAmount, pos uint6
2322 }
2423
2524 // NewCrossChainInput creates a new CrossChainInput.
26-func NewCrossChainInput(mainchainOutputID *Hash, value *AssetAmount, prog *Program, ordinal uint64, assetDef *AssetDefinition) *CrossChainInput {
25+func NewCrossChainInput(mainchainOutputID *Hash, prog *Program, ordinal uint64, assetDef *AssetDefinition) *CrossChainInput {
2726 return &CrossChainInput{
2827 MainchainOutputId: mainchainOutputID,
29- Value: value,
3028 Ordinal: ordinal,
3129 ControlProgram: prog,
3230 AssetDefinition: assetDef,
--- a/protocol/bc/types/block.go
+++ b/protocol/bc/types/block.go
@@ -25,13 +25,15 @@ type Block struct {
2525 Transactions []*Tx
2626 }
2727
28-// MarshalText fulfills the json.Marshaler interface. This guarantees that
29-// blocks will get deserialized correctly when being parsed from HTTP requests.
30-func (b *Block) MarshalText() ([]byte, error) {
28+func (b *Block) marshalText(serflags uint8) ([]byte, error) {
3129 buf := bufpool.Get()
3230 defer bufpool.Put(buf)
3331
34- if _, err := b.WriteTo(buf); err != nil {
32+ ew := errors.NewWriter(buf)
33+ if err := b.writeTo(ew, serflags); err != nil {
34+ return nil, err
35+ }
36+ if err := ew.Err(); err != nil {
3537 return nil, err
3638 }
3739
@@ -40,6 +42,22 @@ func (b *Block) MarshalText() ([]byte, error) {
4042 return enc, nil
4143 }
4244
45+// MarshalText fulfills the json.Marshaler interface. This guarantees that
46+// blocks will get deserialized correctly when being parsed from HTTP requests.
47+func (b *Block) MarshalText() ([]byte, error) {
48+ return b.marshalText(SerBlockFull)
49+}
50+
51+// MarshalTextForBlockHeader fulfills the json.Marshaler interface.
52+func (b *Block) MarshalTextForBlockHeader() ([]byte, error) {
53+ return b.marshalText(SerBlockHeader)
54+}
55+
56+// MarshalTextForTransactions fulfills the json.Marshaler interface.
57+func (b *Block) MarshalTextForTransactions() ([]byte, error) {
58+ return b.marshalText(SerBlockTransactions)
59+}
60+
4361 // UnmarshalText fulfills the encoding.TextUnmarshaler interface.
4462 func (b *Block) UnmarshalText(text []byte) error {
4563 decoded := make([]byte, hex.DecodedLen(len(text)))
@@ -58,42 +76,6 @@ func (b *Block) UnmarshalText(text []byte) error {
5876 return nil
5977 }
6078
61-// MarshalTextForBlockHeader fulfills the json.Marshaler interface.
62-func (b *Block) MarshalTextForBlockHeader() ([]byte, error) {
63- buf := bufpool.Get()
64- defer bufpool.Put(buf)
65-
66- ew := errors.NewWriter(buf)
67- if err := b.writeTo(ew, SerBlockHeader); err != nil {
68- return nil, err
69- }
70- if err := ew.Err(); err != nil {
71- return nil, err
72- }
73-
74- enc := make([]byte, hex.EncodedLen(buf.Len()))
75- hex.Encode(enc, buf.Bytes())
76- return enc, nil
77-}
78-
79-// MarshalTextForTransactions fulfills the json.Marshaler interface.
80-func (b *Block) MarshalTextForTransactions() ([]byte, error) {
81- buf := bufpool.Get()
82- defer bufpool.Put(buf)
83-
84- ew := errors.NewWriter(buf)
85- if err := b.writeTo(ew, SerBlockTransactions); err != nil {
86- return nil, err
87- }
88- if err := ew.Err(); err != nil {
89- return nil, err
90- }
91-
92- enc := make([]byte, hex.EncodedLen(buf.Len()))
93- hex.Encode(enc, buf.Bytes())
94- return enc, nil
95-}
96-
9779 func (b *Block) readFrom(r *blockchain.Reader) error {
9880 serflag, err := b.BlockHeader.readFrom(r)
9981 if err != nil {
@@ -120,7 +102,6 @@ func (b *Block) readFrom(r *blockchain.Reader) error {
120102 return nil
121103 }
122104
123-// WriteTo will write block to input io.Writer
124105 func (b *Block) WriteTo(w io.Writer) (int64, error) {
125106 ew := errors.NewWriter(w)
126107 if err := b.writeTo(ew, SerBlockFull); err != nil {
@@ -130,16 +111,12 @@ func (b *Block) WriteTo(w io.Writer) (int64, error) {
130111 }
131112
132113 func (b *Block) writeTo(w io.Writer, serflags uint8) error {
133- if serflags != SerBlockTransactions {
134- if err := b.BlockHeader.writeTo(w, serflags); err != nil {
135- return err
136- }
114+ if err := b.BlockHeader.writeTo(w, serflags); err != nil {
115+ return err
116+ }
137117
138- if serflags == SerBlockHeader {
139- return nil
140- }
141- } else {
142- w.Write([]byte{serflags})
118+ if serflags == SerBlockHeader {
119+ return nil
143120 }
144121
145122 if _, err := blockchain.WriteVarint31(w, uint64(len(b.Transactions))); err != nil {
--- a/protocol/bc/types/block_header.go
+++ b/protocol/bc/types/block_header.go
@@ -69,7 +69,10 @@ func (bh *BlockHeader) UnmarshalText(text []byte) error {
6969
7070 func (bh *BlockHeader) readFrom(r *blockchain.Reader) (serflag uint8, err error) {
7171 var serflags [1]byte
72- io.ReadFull(r, serflags[:])
72+ if _, err := io.ReadFull(r, serflags[:]); err != nil {
73+ return 0, err
74+ }
75+
7376 serflag = serflags[0]
7477 switch serflag {
7578 case SerBlockHeader, SerBlockFull:
@@ -112,6 +115,10 @@ func (bh *BlockHeader) WriteTo(w io.Writer) (int64, error) {
112115
113116 func (bh *BlockHeader) writeTo(w io.Writer, serflags uint8) (err error) {
114117 w.Write([]byte{serflags})
118+ if serflags == SerBlockTransactions {
119+ return nil
120+ }
121+
115122 if _, err = blockchain.WriteVarint63(w, bh.Version); err != nil {
116123 return err
117124 }
--- a/protocol/bc/types/block_witness.go
+++ b/protocol/bc/types/block_witness.go
@@ -11,13 +11,13 @@ type BlockWitness struct {
1111 Witness [][]byte
1212 }
1313
14-func (bw *BlockWitness) writeTo(w io.Writer) error {
15- _, err := blockchain.WriteVarstrList(w, bw.Witness)
14+func (bw *BlockWitness) readFrom(r *blockchain.Reader) (err error) {
15+ bw.Witness, err = blockchain.ReadVarstrList(r)
1616 return err
1717 }
1818
19-func (bw *BlockWitness) readFrom(r *blockchain.Reader) (err error) {
20- bw.Witness, err = blockchain.ReadVarstrList(r)
19+func (bw *BlockWitness) writeTo(w io.Writer) error {
20+ _, err := blockchain.WriteVarstrList(w, bw.Witness)
2121 return err
2222 }
2323
--- a/protocol/bc/types/block_witness_test.go
+++ b/protocol/bc/types/block_witness_test.go
@@ -82,7 +82,7 @@ func TestBlockWitnessSet(t *testing.T) {
8282 bw: BlockWitness{Witness: [][]byte{[]byte{0x01, 0x02, 0x03, 0x04}, []byte{0x01, 0x02, 0x03, 0x04}}},
8383 index: uint64(4),
8484 data: []byte{0x04, 0x04, 0x04, 0x04},
85- want: BlockWitness{Witness: [][]byte{[]byte{0x01, 0x02, 0x03, 0x04}, []byte{0x01, 0x02, 0x03, 0x04}, []byte{}, []byte{}, []byte{0x04, 0x04, 0x04, 0x04}}},
85+ want: BlockWitness{Witness: [][]byte{[]byte{0x01, 0x02, 0x03, 0x04}, []byte{0x01, 0x02, 0x03, 0x04}, nil, nil, []byte{0x04, 0x04, 0x04, 0x04}}},
8686 },
8787 }
8888
--- a/protocol/bc/types/crosschain_input.go
+++ b/protocol/bc/types/crosschain_input.go
@@ -10,15 +10,15 @@ type CrossChainInput struct {
1010 Arguments [][]byte // Witness
1111 SpendCommitment
1212
13- VMVersion uint64
14- AssetDefinition []byte
15- IssuanceProgram []byte
13+ AssetDefinition []byte
14+ IssuanceVMVersion uint64
15+ IssuanceProgram []byte
1616 }
1717
1818 // NewCrossChainInput create a new CrossChainInput struct.
1919 // The source is created/issued by trusted federation and hence there is no need
2020 // to refer to it.
21-func NewCrossChainInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos, vmVersion uint64, assetDefinition, issuanceProgram []byte) *TxInput {
21+func NewCrossChainInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos, IssuanceVMVersion uint64, assetDefinition, issuanceProgram []byte) *TxInput {
2222 sc := SpendCommitment{
2323 AssetAmount: bc.AssetAmount{
2424 AssetId: &assetID,
@@ -31,11 +31,11 @@ func NewCrossChainInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID
3131 return &TxInput{
3232 AssetVersion: 1,
3333 TypedInput: &CrossChainInput{
34- SpendCommitment: sc,
35- Arguments: arguments,
36- VMVersion: vmVersion,
37- AssetDefinition: assetDefinition,
38- IssuanceProgram: issuanceProgram,
34+ SpendCommitment: sc,
35+ Arguments: arguments,
36+ AssetDefinition: assetDefinition,
37+ IssuanceVMVersion: IssuanceVMVersion,
38+ IssuanceProgram: issuanceProgram,
3939 },
4040 }
4141 }
--- a/protocol/bc/types/map.go
+++ b/protocol/bc/types/map.go
@@ -55,10 +55,9 @@ func MapTx(oldTx *TxData) *bc.Tx {
5555 continue
5656 }
5757
58- if ord >= uint64(len(oldTx.Inputs)) {
59- continue
58+ if ord < uint64(len(oldTx.Inputs)) {
59+ tx.InputIDs[ord] = id
6060 }
61- tx.InputIDs[ord] = id
6261 }
6362
6463 for id := range spentOutputIDs {
@@ -149,18 +148,18 @@ func mapTx(tx *TxData) (headerID bc.Hash, hdr *bc.TxHeader, entryMap map[bc.Hash
149148 }
150149
151150 prevout := bc.NewIntraChainOutput(src, prog, 0) // ordinal doesn't matter
152- outputID := bc.EntryID(prevout)
151+ mainchainOutputID := addEntry(prevout)
153152
154153 assetDefHash := bc.NewHash(sha3.Sum256(inp.AssetDefinition))
155154 assetDef := &bc.AssetDefinition{
156155 Data: &assetDefHash,
157156 IssuanceProgram: &bc.Program{
158- VmVersion: inp.VMVersion,
157+ VmVersion: inp.IssuanceVMVersion,
159158 Code: inp.IssuanceProgram,
160159 },
161160 }
162161
163- crossIn := bc.NewCrossChainInput(&outputID, &inp.AssetAmount, prog, uint64(i), assetDef)
162+ crossIn := bc.NewCrossChainInput(&mainchainOutputID, prog, uint64(i), assetDef)
164163 crossIn.WitnessArguments = inp.Arguments
165164 crossInID := addEntry(crossIn)
166165 muxSources[i] = &bc.ValueSource{
@@ -186,7 +185,8 @@ func mapTx(tx *TxData) (headerID bc.Hash, hdr *bc.TxHeader, entryMap map[bc.Hash
186185 }
187186
188187 for _, crossIn := range crossIns {
189- crossIn.SetDestination(&muxID, crossIn.Value, crossIn.Ordinal)
188+ mainchainOutput := entryMap[*crossIn.MainchainOutputId].(*bc.IntraChainOutput)
189+ crossIn.SetDestination(&muxID, mainchainOutput.Source.Value, crossIn.Ordinal)
190190 }
191191
192192 if coinbase != nil {
@@ -224,7 +224,7 @@ func mapTx(tx *TxData) (headerID bc.Hash, hdr *bc.TxHeader, entryMap map[bc.Hash
224224
225225 case out.OutputType() == VoteOutputType:
226226 // non-retirement vote tx
227- voteOut, _ := out.TypedOutput.(*VoteTxOutput)
227+ voteOut, _ := out.TypedOutput.(*VoteOutput)
228228 prog := &bc.Program{out.VMVersion(), out.ControlProgram()}
229229 o := bc.NewVoteOutput(src, prog, uint64(i), voteOut.Vote)
230230 resultID = addEntry(o)
--- a/protocol/bc/types/output_commitment.go
+++ b/protocol/bc/types/output_commitment.go
@@ -4,7 +4,6 @@ import (
44 "fmt"
55 "io"
66
7- "github.com/vapor/crypto/sha3pool"
87 "github.com/vapor/encoding/blockchain"
98 "github.com/vapor/errors"
109 "github.com/vapor/protocol/bc"
@@ -61,12 +60,3 @@ func (oc *OutputCommitment) readFrom(r *blockchain.Reader, assetVersion uint64)
6160 return nil
6261 })
6362 }
64-
65-// Hash convert suffix && assetVersion to bc.Hash
66-func (oc *OutputCommitment) Hash(suffix []byte, assetVersion uint64) (outputhash bc.Hash) {
67- h := sha3pool.Get256()
68- defer sha3pool.Put256(h)
69- oc.writeExtensibleString(h, suffix, assetVersion)
70- outputhash.ReadFrom(h)
71- return outputhash
72-}
--- a/protocol/bc/types/output_commitment_test.go
+++ b/protocol/bc/types/output_commitment_test.go
@@ -47,8 +47,7 @@ func TestReadWriteOutputCommitment(t *testing.T) {
4747 }
4848
4949 oc := &OutputCommitment{}
50- _, err := oc.readFrom(blockchain.NewReader(buffer.Bytes()), 1)
51- if err != nil {
50+ if _, err := oc.readFrom(blockchain.NewReader(buffer.Bytes()), 1); err != nil {
5251 t.Fatal(err)
5352 }
5453
--- a/protocol/bc/types/txinput.go
+++ b/protocol/bc/types/txinput.go
@@ -32,8 +32,6 @@ type (
3232 }
3333 )
3434
35-var errBadAssetID = errors.New("asset ID does not match other issuance parameters")
36-
3735 // AssetAmount return the asset id and amount of the txinput.
3836 func (t *TxInput) AssetAmount() bc.AssetAmount {
3937 switch inp := t.TypedInput.(type) {
@@ -138,7 +136,7 @@ func (t *TxInput) SpentOutputID() (o bc.Hash, err error) {
138136 o, err = ComputeOutputID(&inp.SpendCommitment, VetoInputType, inp.Vote)
139137 }
140138
141- return o, err
139+ return o, fmt.Errorf("output don't have spend output ID")
142140 }
143141
144142 func (t *TxInput) readFrom(r *blockchain.Reader) (err error) {
@@ -177,11 +175,26 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) {
177175 return err
178176 }
179177
178+ if ci.IssuanceVMVersion, err = blockchain.ReadVarint63(r); err != nil {
179+ return err
180+ }
181+
182+ if ci.AssetDefinition, err = blockchain.ReadVarstr31(r); err != nil {
183+ return err
184+ }
185+
186+ if ci.IssuanceProgram, err = blockchain.ReadVarstr31(r); err != nil {
187+ return err
188+ }
189+
180190 case VetoInputType:
181191 ui := new(VetoInput)
182192 t.TypedInput = ui
183193 if ui.VetoCommitmentSuffix, err = ui.SpendCommitment.readFrom(r, 1); err != nil {
194+ return err
195+ }
184196
197+ if ui.Vote, err = blockchain.ReadVarstr31(r); err != nil {
185198 return err
186199 }
187200
@@ -199,45 +212,21 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) {
199212 return nil
200213 }
201214
215+ var err error
202216 switch inp := t.TypedInput.(type) {
203217 case *SpendInput:
204- if inp.Arguments, err = blockchain.ReadVarstrList(r); err != nil {
205- return err
206- }
218+ inp.Arguments, err = blockchain.ReadVarstrList(r)
207219
208220 case *CrossChainInput:
209- if inp.Arguments, err = blockchain.ReadVarstrList(r); err != nil {
210- return err
211- }
212-
213- if inp.VMVersion, err = blockchain.ReadVarint63(r); err != nil {
214- return err
215- }
216-
217- if inp.AssetDefinition, err = blockchain.ReadVarstr31(r); err != nil {
218- return err
219- }
220-
221- if inp.IssuanceProgram, err = blockchain.ReadVarstr31(r); err != nil {
222- return err
223- }
221+ inp.Arguments, err = blockchain.ReadVarstrList(r)
224222
225223 case *VetoInput:
226- if inp.Arguments, err = blockchain.ReadVarstrList(r); err != nil {
227- return err
228- }
229- if inp.Vote, err = blockchain.ReadVarstr31(r); err != nil {
230- return err
231- }
232-
224+ inp.Arguments, err = blockchain.ReadVarstrList(r)
233225 }
234- return nil
235- })
236- if err != nil {
237- return err
238- }
239226
240- return nil
227+ return err
228+ })
229+ return err
241230 }
242231
243232 func (t *TxInput) writeTo(w io.Writer) error {
@@ -266,19 +255,36 @@ func (t *TxInput) writeInputCommitment(w io.Writer) (err error) {
266255 if _, err = w.Write([]byte{SpendInputType}); err != nil {
267256 return err
268257 }
258+
269259 return inp.SpendCommitment.writeExtensibleString(w, inp.SpendCommitmentSuffix, t.AssetVersion)
270260
271261 case *CrossChainInput:
272262 if _, err = w.Write([]byte{CrossChainInputType}); err != nil {
273263 return err
274264 }
275- return inp.SpendCommitment.writeExtensibleString(w, inp.SpendCommitmentSuffix, t.AssetVersion)
265+
266+ if err := inp.SpendCommitment.writeExtensibleString(w, inp.SpendCommitmentSuffix, t.AssetVersion); err != nil {
267+ return err
268+ }
269+
270+ if _, err := blockchain.WriteVarint63(w, inp.IssuanceVMVersion); err != nil {
271+ return err
272+ }
273+
274+ if _, err := blockchain.WriteVarstr31(w, inp.AssetDefinition); err != nil {
275+ return err
276+ }
277+
278+ if _, err := blockchain.WriteVarstr31(w, inp.IssuanceProgram); err != nil {
279+ return err
280+ }
276281
277282 case *CoinbaseInput:
278- if _, err = w.Write([]byte{CoinbaseInputType}); err != nil {
283+ if _, err := w.Write([]byte{CoinbaseInputType}); err != nil {
279284 return err
280285 }
281- if _, err = blockchain.WriteVarstr31(w, inp.Arbitrary); err != nil {
286+
287+ if _, err := blockchain.WriteVarstr31(w, inp.Arbitrary); err != nil {
282288 return errors.Wrap(err, "writing coinbase arbitrary")
283289 }
284290
@@ -286,7 +292,13 @@ func (t *TxInput) writeInputCommitment(w io.Writer) (err error) {
286292 if _, err = w.Write([]byte{VetoInputType}); err != nil {
287293 return err
288294 }
289- return inp.SpendCommitment.writeExtensibleString(w, inp.VetoCommitmentSuffix, t.AssetVersion)
295+
296+ if err := inp.SpendCommitment.writeExtensibleString(w, inp.VetoCommitmentSuffix, t.AssetVersion); err != nil {
297+ return err
298+ }
299+
300+ _, err := blockchain.WriteVarstr31(w, inp.Vote)
301+ return err
290302 }
291303 return nil
292304 }
@@ -296,33 +308,16 @@ func (t *TxInput) writeInputWitness(w io.Writer) error {
296308 return nil
297309 }
298310
311+ var err error
299312 switch inp := t.TypedInput.(type) {
300313 case *SpendInput:
301- _, err := blockchain.WriteVarstrList(w, inp.Arguments)
302- return err
314+ _, err = blockchain.WriteVarstrList(w, inp.Arguments)
303315
304316 case *CrossChainInput:
305- if _, err := blockchain.WriteVarstrList(w, inp.Arguments); err != nil {
306- return err
307- }
317+ _, err = blockchain.WriteVarstrList(w, inp.Arguments)
308318
309- if _, err := blockchain.WriteVarint63(w, inp.VMVersion); err != nil {
310- return err
311- }
312-
313- if _, err := blockchain.WriteVarstr31(w, inp.AssetDefinition); err != nil {
314- return err
315- }
316-
317- _, err := blockchain.WriteVarstr31(w, inp.IssuanceProgram)
318-
319- return err
320319 case *VetoInput:
321- if _, err := blockchain.WriteVarstrList(w, inp.Arguments); err != nil {
322- return err
323- }
324- _, err := blockchain.WriteVarstr31(w, inp.Vote)
325- return err
320+ _, err = blockchain.WriteVarstrList(w, inp.Arguments)
326321 }
327- return nil
322+ return err
328323 }
--- a/protocol/bc/types/txinput_test.go
+++ b/protocol/bc/types/txinput_test.go
@@ -76,7 +76,7 @@ func TestSerializationCrossIn(t *testing.T) {
7676
7777 wantHex := strings.Join([]string{
7878 "01", // asset version
79- "48", // input commitment length
79+ "62", // input commitment length
8080 "00", // cross-chain input type flag
8181 "46", // cross-chain input commitment length
8282 "fad5195a0c8e3b590b86a3c0a95e7529565888508aecca96e9aeda633002f409", // source id
@@ -85,17 +85,17 @@ func TestSerializationCrossIn(t *testing.T) {
8585 "03", // source position
8686 "01", // vm version
8787 "00", // spend program length
88- "31", // witness length
89- "02", // argument array length
90- "0a", // first argument length
91- "617267756d656e747331", // first argument data
92- "0a", // second argument length
93- "617267756d656e747332", // second argument data
9488 "01", // VmVersion
9589 "08", // asset definition length
9690 "7768617465766572", // asset definition data
9791 "0f", // IssuanceProgram length
9892 "49737375616e636550726f6772616d", // IssuanceProgram
93+ "17", // witness length
94+ "02", // argument array length
95+ "0a", // first argument length
96+ "617267756d656e747331", // first argument data
97+ "0a", // second argument length
98+ "617267756d656e747332", // second argument data
9999 }, "")
100100
101101 // Test convert struct to hex
@@ -134,10 +134,10 @@ func TestSerializationVeto(t *testing.T) {
134134 vetoInput := NewVetoInput(arguments, testutil.MustDecodeHash("fad5195a0c8e3b590b86a3c0a95e7529565888508aecca96e9aeda633002f409"), testutil.MustDecodeAsset("fe9791d71b67ee62515e08723c061b5ccb952a80d804417c8aeedf7f633c524a"), 254354, 3, []byte("spendProgram"), []byte("af594006a40837d9f028daabb6d589df0b9138daefad5683e5233c2646279217294a8d532e60863bcf196625a35fb8ceeffa3c09610eb92dcfb655a947f13269"))
135135
136136 wantHex := strings.Join([]string{
137- "01", // asset version
138- "54", // input commitment length
139- "03", // veto type flag
140- "52", // veto commitment length
137+ "01", // asset version
138+ "d601", // input commitment length
139+ "03", // veto type flag
140+ "52", // veto commitment length
141141 "fad5195a0c8e3b590b86a3c0a95e7529565888508aecca96e9aeda633002f409", // source id
142142 "fe9791d71b67ee62515e08723c061b5ccb952a80d804417c8aeedf7f633c524a", // assetID
143143 "92c30f", // amount
@@ -145,14 +145,14 @@ func TestSerializationVeto(t *testing.T) {
145145 "01", // vm version
146146 "0c", // veto program length
147147 "7370656e6450726f6772616d", // veto program
148- "9901", // witness length
149- "02", // argument array length
150- "0a", // first argument length
151- "617267756d656e747331", // first argument data
152- "0a", // second argument length
153- "617267756d656e747332", // second argument data
154148 "8001", //xpub length
155149 "6166353934303036613430383337643966303238646161626236643538396466306239313338646165666164353638336535323333633236343632373932313732393461386435333265363038363362636631393636323561333566623863656566666133633039363130656239326463666236353561393437663133323639", //voter xpub
150+ "17", // witness length
151+ "02", // argument array length
152+ "0a", // first argument length
153+ "617267756d656e747331", // first argument data
154+ "0a", // second argument length
155+ "617267756d656e747332", // second argument data
156156 }, "")
157157
158158 // Test convert struct to hex
--- a/protocol/bc/types/txoutput.go
+++ b/protocol/bc/types/txoutput.go
@@ -40,7 +40,7 @@ func (to *TxOutput) OutputCommitment() OutputCommitment {
4040 case *CrossChainOutput:
4141 return outp.OutputCommitment
4242
43- case *VoteTxOutput:
43+ case *VoteOutput:
4444 return outp.OutputCommitment
4545
4646 default:
@@ -57,7 +57,7 @@ func (to *TxOutput) AssetAmount() bc.AssetAmount {
5757 case *CrossChainOutput:
5858 return outp.AssetAmount
5959
60- case *VoteTxOutput:
60+ case *VoteOutput:
6161 return outp.AssetAmount
6262
6363 default:
@@ -74,7 +74,7 @@ func (to *TxOutput) ControlProgram() []byte {
7474 case *CrossChainOutput:
7575 return outp.ControlProgram
7676
77- case *VoteTxOutput:
77+ case *VoteOutput:
7878 return outp.ControlProgram
7979
8080 default:
@@ -91,7 +91,7 @@ func (to *TxOutput) VMVersion() uint64 {
9191 case *CrossChainOutput:
9292 return outp.VMVersion
9393
94- case *VoteTxOutput:
94+ case *VoteOutput:
9595 return outp.VMVersion
9696
9797 default:
@@ -130,7 +130,7 @@ func (to *TxOutput) readFrom(r *blockchain.Reader) (err error) {
130130 }
131131
132132 case VoteOutputType:
133- out := new(VoteTxOutput)
133+ out := new(VoteOutput)
134134 to.TypedOutput = out
135135 if out.Vote, err = blockchain.ReadVarstr31(r); err != nil {
136136 return errors.Wrap(err, "reading vote output vote")
@@ -190,7 +190,7 @@ func (to *TxOutput) writeOutputCommitment(w io.Writer) error {
190190 }
191191 return outp.OutputCommitment.writeExtensibleString(w, outp.CommitmentSuffix, to.AssetVersion)
192192
193- case *VoteTxOutput:
193+ case *VoteOutput:
194194 if _, err := w.Write([]byte{VoteOutputType}); err != nil {
195195 return err
196196 }
--- a/protocol/bc/types/txoutput_test.go
+++ b/protocol/bc/types/txoutput_test.go
@@ -99,7 +99,7 @@ func TestSerializationCrossChainTxOutput(t *testing.T) {
9999 }
100100 }
101101
102-func TestSerializationVoteTxOutput(t *testing.T) {
102+func TestSerializationVoteOutput(t *testing.T) {
103103 assetID := testutil.MustDecodeAsset("81756fdab39a17163b0ce582ee4ee256fb4d1e156c692b997d608a42ecb38d47")
104104 voteTxOutput := NewVoteOutput(assetID, 1000, []byte("TestSerializationTxOutput"), []byte("af594006a40837d9f028daabb6d589df0b9138daefad5683e5233c2646279217294a8d532e60863bcf196625a35fb8ceeffa3c09610eb92dcfb655a947f13269"))
105105
--- a/protocol/bc/types/vote_txoutput.go
+++ b/protocol/bc/types/vote_output.go
@@ -4,8 +4,8 @@ import (
44 "github.com/vapor/protocol/bc"
55 )
66
7-// VoteTxOutput satisfies the TypedOutput interface and represents a vote transaction.
8-type VoteTxOutput struct {
7+// VoteOutput satisfies the TypedOutput interface and represents a vote transaction.
8+type VoteOutput struct {
99 OutputCommitment
1010 // Unconsumed suffixes of the commitment and witness extensible strings.
1111 CommitmentSuffix []byte
@@ -16,7 +16,7 @@ type VoteTxOutput struct {
1616 func NewVoteOutput(assetID bc.AssetID, amount uint64, controlProgram []byte, vote []byte) *TxOutput {
1717 return &TxOutput{
1818 AssetVersion: 1,
19- TypedOutput: &VoteTxOutput{
19+ TypedOutput: &VoteOutput{
2020 OutputCommitment: OutputCommitment{
2121 AssetAmount: bc.AssetAmount{
2222 AssetId: &assetID,
@@ -30,4 +30,4 @@ func NewVoteOutput(assetID bc.AssetID, amount uint64, controlProgram []byte, vot
3030 }
3131 }
3232
33-func (it *VoteTxOutput) OutputType() uint8 { return VoteOutputType }
33+func (it *VoteOutput) OutputType() uint8 { return VoteOutputType }
--- a/protocol/state/vote_result.go
+++ b/protocol/state/vote_result.go
@@ -75,7 +75,7 @@ func (v *VoteResult) ApplyBlock(block *types.Block) error {
7575 }
7676
7777 for _, output := range tx.Outputs {
78- voteOutput, ok := output.TypedOutput.(*types.VoteTxOutput)
78+ voteOutput, ok := output.TypedOutput.(*types.VoteOutput)
7979 if !ok {
8080 continue
8181 }
@@ -148,7 +148,7 @@ func (v *VoteResult) DetachBlock(block *types.Block) error {
148148 }
149149
150150 for _, output := range tx.Outputs {
151- voteOutput, ok := output.TypedOutput.(*types.VoteTxOutput)
151+ voteOutput, ok := output.TypedOutput.(*types.VoteOutput)
152152 if !ok {
153153 continue
154154 }
--- a/protocol/validation/tx.go
+++ b/protocol/validation/tx.go
@@ -251,9 +251,17 @@ func checkValid(vs *validationState, e bc.Entry) (err error) {
251251 }
252252
253253 case *bc.CrossChainInput:
254- // check assetID
254+ if e.MainchainOutputId == nil {
255+ return errors.Wrap(ErrMissingField, "crosschain input without mainchain output ID")
256+ }
257+
258+ mainchainOutput, err := vs.tx.IntraChainOutput(*e.MainchainOutputId)
259+ if err != nil {
260+ return errors.Wrap(err, "getting mainchain output")
261+ }
262+
255263 assetID := e.AssetDefinition.ComputeAssetID()
256- if *e.Value.AssetId != *consensus.BTMAssetID && *e.Value.AssetId != assetID {
264+ if *mainchainOutput.Source.Value.AssetId != *consensus.BTMAssetID && *mainchainOutput.Source.Value.AssetId != assetID {
257265 return errors.New("incorrect asset_id while checking CrossChainInput")
258266 }
259267
@@ -262,8 +270,8 @@ func checkValid(vs *validationState, e bc.Entry) (err error) {
262270 VmVersion: e.ControlProgram.VmVersion,
263271 Code: code,
264272 }
265- _, err := vm.Verify(NewTxVMContext(vs, e, prog, e.WitnessArguments), consensus.DefaultGasCredit)
266- if err != nil {
273+
274+ if _, err := vm.Verify(NewTxVMContext(vs, e, prog, e.WitnessArguments), consensus.DefaultGasCredit); err != nil {
267275 return errors.Wrap(err, "checking cross-chain input control program")
268276 }
269277
--- a/protocol/validation/vmcontext.go
+++ b/protocol/validation/vmcontext.go
@@ -26,10 +26,13 @@ func NewTxVMContext(vs *validationState, entry bc.Entry, prog *bc.Program, args
2626
2727 switch e := entry.(type) {
2828 case *bc.CrossChainInput:
29- a1 := e.Value.AssetId.Bytes()
29+ mainchainOutput := tx.Entries[*e.MainchainOutputId].(*bc.IntraChainOutput)
30+ a1 := mainchainOutput.Source.Value.AssetId.Bytes()
3031 assetID = &a1
31- amount = &e.Value.Amount
32+ amount = &mainchainOutput.Source.Value.Amount
3233 destPos = &e.WitnessDestination.Position
34+ s := e.MainchainOutputId.Bytes()
35+ spentOutputID = &s
3336
3437 case *bc.Spend:
3538 spentOutput := tx.Entries[*e.SpentOutputId].(*bc.IntraChainOutput)
--- a/testutil/expect.go
+++ /dev/null
@@ -1,27 +0,0 @@
1-package testutil
2-
3-import (
4- "fmt"
5- "os"
6- "path/filepath"
7- "strings"
8- "testing"
9-
10- "github.com/vapor/errors"
11-)
12-
13-var wd, _ = os.Getwd()
14-
15-func FatalErr(t testing.TB, err error) {
16- args := []interface{}{err}
17- for _, frame := range errors.Stack(err) {
18- file := frame.File
19- if rel, err := filepath.Rel(wd, file); err == nil && !strings.HasPrefix(rel, "../") {
20- file = rel
21- }
22- funcname := frame.Func[strings.IndexByte(frame.Func, '.')+1:]
23- s := fmt.Sprintf("\n%s:%d: %s", file, frame.Line, funcname)
24- args = append(args, s)
25- }
26- t.Fatal(args...)
27-}
--- a/testutil/parameter.go
+++ /dev/null
@@ -1,10 +0,0 @@
1-package testutil
2-
3-import (
4- "github.com/vapor/protocol/bc"
5-)
6-
7-var (
8- MaxHash = &bc.Hash{V0: 1<<64 - 1, V1: 1<<64 - 1, V2: 1<<64 - 1, V3: 1<<64 - 1}
9- MinHash = &bc.Hash{}
10-)
--- a/wallet/utxo_test.go
+++ b/wallet/utxo_test.go
@@ -684,35 +684,35 @@ func TestTxOutToUtxos(t *testing.T) {
684684 blockHeight: 0,
685685 wantUtxos: []*account.UTXO{
686686 &account.UTXO{
687- OutputID: bc.Hash{V0: 5429526025956869574, V1: 12188959875155232503, V2: 14722092106507294798, V3: 27876074648890075},
687+ OutputID: bc.Hash{15099088327605875240, 9219883424533839002, 14610773420520931246, 14899393216621986426},
688688 AssetID: bc.AssetID{V0: 1},
689689 Amount: 2,
690690 ControlProgram: []byte{0x51},
691- SourceID: bc.Hash{V0: 10187915247323429348, V1: 4770401581694266753, V2: 4182269187154655368, V3: 9030883832705174512},
691+ SourceID: bc.Hash{16280523637332892554, 3627898494554775182, 16212395834831293013, 3511838375364469081},
692692 SourcePos: 0,
693693 },
694694 &account.UTXO{
695- OutputID: bc.Hash{V0: 18100481287404207387, V1: 3365694797435565990, V2: 8136211093499423216, V3: 12028531817690438568},
695+ OutputID: bc.Hash{3610727630628260133, 13088239834060115701, 14968571476177322101, 7529789620153710893},
696696 AssetID: bc.AssetID{V0: 1},
697697 Amount: 3,
698698 ControlProgram: []byte{0x52},
699- SourceID: bc.Hash{V0: 10187915247323429348, V1: 4770401581694266753, V2: 4182269187154655368, V3: 9030883832705174512},
699+ SourceID: bc.Hash{16280523637332892554, 3627898494554775182, 16212395834831293013, 3511838375364469081},
700700 SourcePos: 1,
701701 },
702702 &account.UTXO{
703- OutputID: bc.Hash{V0: 15745816911932387102, V1: 5035893487696724781, V2: 10084725527786878517, V3: 11270352747873435606},
703+ OutputID: bc.Hash{2034718018519539988, 16893043149780417913, 11926903829554245570, 3446441680088007327},
704704 AssetID: *consensus.BTMAssetID,
705705 Amount: 2,
706706 ControlProgram: []byte{0x53},
707- SourceID: bc.Hash{V0: 10187915247323429348, V1: 4770401581694266753, V2: 4182269187154655368, V3: 9030883832705174512},
707+ SourceID: bc.Hash{16280523637332892554, 3627898494554775182, 16212395834831293013, 3511838375364469081},
708708 SourcePos: 2,
709709 },
710710 &account.UTXO{
711- OutputID: bc.Hash{V0: 10165799535720725897, V1: 9618876671942765420, V2: 17982649347111502590, V3: 15837286550437859084},
711+ OutputID: bc.Hash{7296157888262317106, 5789265653020263821, 1170213393196090227, 7665081318694049454},
712712 AssetID: *consensus.BTMAssetID,
713713 Amount: 5,
714714 ControlProgram: []byte{0x54},
715- SourceID: bc.Hash{V0: 10187915247323429348, V1: 4770401581694266753, V2: 4182269187154655368, V3: 9030883832705174512},
715+ SourceID: bc.Hash{16280523637332892554, 3627898494554775182, 16212395834831293013, 3511838375364469081},
716716 SourcePos: 3,
717717 },
718718 },
Show on old repository browser