Skip to content

Commit 3e728b9

Browse files
sukrawidhyawanandy-shi88
authored andcommitted
107 Init Datasets (was Set Account Properties) (#156)
* datasets: add table migration * dataset: add query and dataset transaction type * mempool: bug fix when remove tx in mempol * add client post transaction * mempool: test case DeleteMempoolTransactions * add test case: dataset query & tx setupDataset * remove address length * setupDataset: update err format * schema: update submodule schema * remove tx.Validate on ApplyConfirmed or ApplyUnconfirmed * api client : get api port from config * transaction: remove unused test case * change model.Dataset to model.AccountDataset
1 parent d5ea2bf commit 3e728b9

30 files changed

+1822
-138
lines changed

api/client/GetAccountBalance/client.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56

7+
"github.com/sirupsen/logrus"
68
log "github.com/sirupsen/logrus"
9+
"github.com/spf13/viper"
710
rpc_model "github.com/zoobc/zoobc-core/common/model"
811
rpc_service "github.com/zoobc/zoobc-core/common/service"
12+
"github.com/zoobc/zoobc-core/common/util"
913
"google.golang.org/grpc"
1014
)
1115

1216
func main() {
13-
conn, err := grpc.Dial(":3001", grpc.WithInsecure())
17+
var apiRPCPort int
18+
if err := util.LoadConfig("../../../resource", "config", "toml"); err != nil {
19+
logrus.Fatal(err)
20+
} else {
21+
apiRPCPort = viper.GetInt("apiRPCPort")
22+
if apiRPCPort == 0 {
23+
apiRPCPort = 8080
24+
}
25+
}
26+
27+
conn, err := grpc.Dial(fmt.Sprintf(":%d", apiRPCPort), grpc.WithInsecure())
1428
if err != nil {
1529
log.Fatalf("did not connect: %s", err)
1630
}

api/client/GetBlockByHeight/client.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56

7+
"github.com/sirupsen/logrus"
68
log "github.com/sirupsen/logrus"
9+
"github.com/spf13/viper"
710
rpc_model "github.com/zoobc/zoobc-core/common/model"
811
rpc_service "github.com/zoobc/zoobc-core/common/service"
12+
"github.com/zoobc/zoobc-core/common/util"
913
"google.golang.org/grpc"
1014
)
1115

1216
func main() {
13-
conn, err := grpc.Dial(":8000", grpc.WithInsecure())
17+
var apiRPCPort int
18+
if err := util.LoadConfig("../../../resource", "config", "toml"); err != nil {
19+
logrus.Fatal(err)
20+
} else {
21+
apiRPCPort = viper.GetInt("apiRPCPort")
22+
if apiRPCPort == 0 {
23+
apiRPCPort = 8080
24+
}
25+
}
26+
27+
conn, err := grpc.Dial(fmt.Sprintf(":%d", apiRPCPort), grpc.WithInsecure())
1428
if err != nil {
1529
log.Fatalf("did not connect: %s", err)
1630
}

api/client/GetBlockByID/client.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56

7+
"github.com/sirupsen/logrus"
68
log "github.com/sirupsen/logrus"
9+
"github.com/spf13/viper"
710
rpc_model "github.com/zoobc/zoobc-core/common/model"
811
rpc_service "github.com/zoobc/zoobc-core/common/service"
12+
"github.com/zoobc/zoobc-core/common/util"
913
"google.golang.org/grpc"
1014
)
1115

1216
func main() {
13-
conn, err := grpc.Dial(":3001", grpc.WithInsecure())
17+
var apiRPCPort int
18+
if err := util.LoadConfig("../../../resource", "config", "toml"); err != nil {
19+
logrus.Fatal(err)
20+
} else {
21+
apiRPCPort = viper.GetInt("apiRPCPort")
22+
if apiRPCPort == 0 {
23+
apiRPCPort = 8080
24+
}
25+
}
26+
27+
conn, err := grpc.Dial(fmt.Sprintf(":%d", apiRPCPort), grpc.WithInsecure())
1428
if err != nil {
1529
log.Fatalf("did not connect: %s", err)
1630
}

api/client/GetBlocks/client.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56

7+
"github.com/sirupsen/logrus"
68
log "github.com/sirupsen/logrus"
9+
"github.com/spf13/viper"
710
rpc_model "github.com/zoobc/zoobc-core/common/model"
811
rpc_service "github.com/zoobc/zoobc-core/common/service"
12+
"github.com/zoobc/zoobc-core/common/util"
913
"google.golang.org/grpc"
1014
)
1115

1216
func main() {
13-
conn, err := grpc.Dial(":3001", grpc.WithInsecure())
17+
var apiRPCPort int
18+
if err := util.LoadConfig("../../../resource", "config", "toml"); err != nil {
19+
logrus.Fatal(err)
20+
} else {
21+
apiRPCPort = viper.GetInt("apiRPCPort")
22+
if apiRPCPort == 0 {
23+
apiRPCPort = 8080
24+
}
25+
}
26+
27+
conn, err := grpc.Dial(fmt.Sprintf(":%d", apiRPCPort), grpc.WithInsecure())
1428
if err != nil {
1529
log.Fatalf("did not connect: %s", err)
1630
}

api/client/GetProofOfOwnership/client.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ package main
33
import (
44
"bytes"
55
"context"
6+
"fmt"
67

8+
"github.com/sirupsen/logrus"
79
log "github.com/sirupsen/logrus"
10+
"github.com/spf13/viper"
811
"github.com/zoobc/zoobc-core/common/crypto"
912
rpc_model "github.com/zoobc/zoobc-core/common/model"
1013
rpc_service "github.com/zoobc/zoobc-core/common/service"
@@ -13,7 +16,17 @@ import (
1316
)
1417

1518
func main() {
16-
conn, err := grpc.Dial(":3001", grpc.WithInsecure())
19+
var apiRPCPort int
20+
if err := util.LoadConfig("../../../resource", "config", "toml"); err != nil {
21+
logrus.Fatal(err)
22+
} else {
23+
apiRPCPort = viper.GetInt("apiRPCPort")
24+
if apiRPCPort == 0 {
25+
apiRPCPort = 8080
26+
}
27+
}
28+
29+
conn, err := grpc.Dial(fmt.Sprintf(":%d", apiRPCPort), grpc.WithInsecure())
1730
if err != nil {
1831
log.Fatalf("did not connect: %s", err)
1932
}

api/client/GetTransaction/client.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56

7+
"github.com/sirupsen/logrus"
68
log "github.com/sirupsen/logrus"
9+
"github.com/spf13/viper"
710
rpc_model "github.com/zoobc/zoobc-core/common/model"
811
rpc_service "github.com/zoobc/zoobc-core/common/service"
12+
"github.com/zoobc/zoobc-core/common/util"
913
"google.golang.org/grpc"
1014
)
1115

1216
func main() {
13-
conn, err := grpc.Dial(":8000", grpc.WithInsecure())
17+
var apiRPCPort int
18+
if err := util.LoadConfig("../../../resource", "config", "toml"); err != nil {
19+
logrus.Fatal(err)
20+
} else {
21+
apiRPCPort = viper.GetInt("apiRPCPort")
22+
if apiRPCPort == 0 {
23+
apiRPCPort = 8080
24+
}
25+
}
26+
27+
conn, err := grpc.Dial(fmt.Sprintf(":%d", apiRPCPort), grpc.WithInsecure())
1428
if err != nil {
1529
log.Fatalf("did not connect: %s", err)
1630
}

api/client/GetTransactions/client.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56

7+
"github.com/sirupsen/logrus"
68
log "github.com/sirupsen/logrus"
9+
"github.com/spf13/viper"
710
rpcModel "github.com/zoobc/zoobc-core/common/model"
811
rpcService "github.com/zoobc/zoobc-core/common/service"
12+
"github.com/zoobc/zoobc-core/common/util"
913
"google.golang.org/grpc"
1014
)
1115

1216
func main() {
13-
conn, err := grpc.Dial(":3001", grpc.WithInsecure())
17+
var apiRPCPort int
18+
if err := util.LoadConfig("../../../resource", "config", "toml"); err != nil {
19+
logrus.Fatal(err)
20+
} else {
21+
apiRPCPort = viper.GetInt("apiRPCPort")
22+
if apiRPCPort == 0 {
23+
apiRPCPort = 8080
24+
}
25+
}
26+
27+
conn, err := grpc.Dial(fmt.Sprintf(":%d", apiRPCPort), grpc.WithInsecure())
1428
if err != nil {
1529
log.Fatalf("did not connect: %s", err)
1630
}

api/client/PostTransaction/client.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56

7+
"github.com/sirupsen/logrus"
68
log "github.com/sirupsen/logrus"
9+
"github.com/spf13/viper"
710
rpc_model "github.com/zoobc/zoobc-core/common/model"
811
rpc_service "github.com/zoobc/zoobc-core/common/service"
12+
"github.com/zoobc/zoobc-core/common/util"
913
"google.golang.org/grpc"
1014
)
1115

1216
func main() {
13-
conn, err := grpc.Dial(":3001", grpc.WithInsecure())
17+
var apiRPCPort int
18+
if err := util.LoadConfig("../../../resource", "config", "toml"); err != nil {
19+
logrus.Fatal(err)
20+
} else {
21+
apiRPCPort = viper.GetInt("apiRPCPort")
22+
if apiRPCPort == 0 {
23+
apiRPCPort = 8080
24+
}
25+
}
26+
27+
conn, err := grpc.Dial(fmt.Sprintf(":%d", apiRPCPort), grpc.WithInsecure())
1428
if err != nil {
1529
log.Fatalf("did not connect: %s", err)
1630
}
@@ -53,6 +67,21 @@ func main() {
5367
// 132, 107, 152, 95, 198, 96, 238, 88, 8, 76, 24, 42, 139, 71, 249, 178, 252, 59, 30, 57, 74, 146, 163, 211, 36, 110, 221, 219, 218,
5468
// 57, 63, 79, 55, 216, 214, 139, 85, 125, 62, 129, 158, 16, 108, 3,
5569
// },
70+
71+
// setup Dataset
72+
// TransactionBytes: []byte{
73+
// 3, 0, 0, 0, 1, 92, 108, 83, 93, 0, 0, 0, 0, 44, 0, 0, 0, 66, 67, 90, 110, 83, 102, 113, 112, 80, 53, 116, 113, 70, 81, 108,
74+
// 77, 84, 89, 107, 68, 101, 66, 86, 70, 87, 110, 98, 121, 86, 75, 55, 118, 76, 114, 53, 79, 82, 70, 112, 84, 106, 103, 116,
75+
// 78, 44, 0, 0, 0, 66, 67, 90, 75, 76, 118, 103, 85, 89, 90, 49, 75, 75, 120, 45, 106, 116, 70, 57, 75, 111, 74, 115, 107, 106,
76+
// 86, 80, 118, 66, 57, 106, 112, 73, 106, 102, 122, 122, 73, 54, 122, 68, 87, 48, 74, 1, 0, 0, 0, 0, 0, 0, 0, 131, 0, 0, 0,
77+
// 44, 0, 0, 0, 66, 67, 90, 110, 83, 102, 113, 112, 80, 53, 116, 113, 70, 81, 108, 77, 84, 89, 107, 68, 101, 66, 86, 70, 87,
78+
// 110, 98, 121, 86, 75, 55, 118, 76, 114, 53, 79, 82, 70, 112, 84, 106, 103, 116, 78, 44, 0, 0, 0, 66, 67, 90, 75, 76, 118, 103,
79+
// 85, 89, 90, 49, 75, 75, 120, 45, 106, 116, 70, 57, 75, 111, 74, 115, 107, 106, 86, 80, 118, 66, 57, 106, 112, 73, 106, 102,
80+
// 122, 122, 73, 54, 122, 68, 87, 48, 74, 5, 0, 0, 0, 65, 100, 109, 105, 110, 14, 0, 0, 0, 121, 111, 117, 114, 32, 97, 114, 101,
81+
// 32, 97, 100, 109, 105, 110, 0, 141, 39, 0, 0, 0, 0, 0, 49, 195, 165, 218, 129, 183, 199, 241, 41, 12, 132, 139, 76, 252, 226,
82+
// 91, 5, 96, 72, 140, 247, 72, 100, 67, 148, 188, 226, 179, 71, 94, 87, 191, 147, 220, 243, 199, 102, 104, 155, 203, 82, 23,
83+
// 255, 170, 37, 39, 65, 195, 54, 30, 184, 46, 230, 222, 62, 138, 79, 69, 22, 191, 34, 9, 81, 4,
84+
// },
5685
})
5786

5887
if err != nil {

cmd/transaction/transactionGenerator.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
var txTypeMap = map[string][]byte{
1919
"sendMoney": {1, 0, 0, 0},
2020
"registerNode": {2, 0, 0, 0},
21+
"setupDataset": {3, 0, 0, 0},
2122
}
2223

2324
func GenerateTransactionBytes(logger *logrus.Logger,
@@ -111,6 +112,30 @@ func getTransaction(txType []byte) *model.Transaction {
111112
},
112113
TransactionBodyBytes: txBodyBytes,
113114
}
115+
case util.ConvertBytesToUint32(txTypeMap["setupDataset"]):
116+
txBody := &model.SetupAccountDatasetTransactionBody{
117+
SetterAccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN",
118+
RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J",
119+
Property: "Member",
120+
Value: "Welcome to the jungle",
121+
MuchTime: 2592000, // 30 days in second
122+
}
123+
txBodyBytes := (&transaction.SetupAccountDataset{
124+
Body: txBody,
125+
}).GetBodyBytes()
126+
return &model.Transaction{
127+
Version: 1,
128+
TransactionType: util.ConvertBytesToUint32(txTypeMap["setupDataset"]),
129+
Timestamp: time.Now().Unix(),
130+
SenderAccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN",
131+
RecipientAccountAddress: "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J",
132+
Fee: 1,
133+
TransactionBodyLength: uint32(len(txBodyBytes)),
134+
TransactionBody: &model.Transaction_SetupAccountDatasetTransactionBody{
135+
SetupAccountDatasetTransactionBody: txBody,
136+
},
137+
TransactionBodyBytes: txBodyBytes,
138+
}
114139
}
115140
return nil
116141
}

common/constant/fieldsSize.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ var (
1818
TransactionBodyLength uint32 = 4
1919
// AccountSignature TODO: this is valid for signatures using Ed25519. in future we might have more implementations
2020
AccountSignature uint32 = 64
21+
22+
// DatasetPropertyLength is max length of string property name in dataset
23+
DatasetPropertyLength uint32 = 4
24+
// DatasetValueLength is max length of string property value in dataset
25+
DatasetValueLength uint32 = 4
2126
)

common/database/migration.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ func (m *Migration) Init() error {
110110
UNIQUE ("account_address", "height"),
111111
PRIMARY KEY("id", "height")
112112
);`,
113+
`
114+
CREATE TABLE IF NOT EXISTS "account_dataset"(
115+
"setter_account_address" VARCHAR(255),
116+
"recipient_account_address" VARCHAR(255),
117+
"property" TEXT,
118+
"value" TEXT,
119+
"timestamp_starts" INTEGER,
120+
"timestamp_expires" INTEGER,
121+
"height" INTEGER,
122+
"latest" INTEGER,
123+
PRIMARY KEY("setter_account_address","recipient_account_address", "property", "height")
124+
);`,
113125
}
114126
return nil
115127
}

0 commit comments

Comments
 (0)