MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / Create

Function Create

test/helper.go:60–109  ·  view source on GitHub ↗

Create allocates new database.

(
	meta types.ResourceMeta,
	gasPrice uint64,
	advancePayment uint64,
	privateKey *asymmetric.PrivateKey,
)

Source from the content-addressed store, hash-verified

58
59// Create allocates new database.
60func Create(
61 meta types.ResourceMeta,
62 gasPrice uint64,
63 advancePayment uint64,
64 privateKey *asymmetric.PrivateKey,
65) (
66 dbID proto.DatabaseID, dsn string, err error,
67) {
68 var (
69 nonceReq = new(types.NextAccountNonceReq)
70 nonceResp = new(types.NextAccountNonceResp)
71 req = new(types.AddTxReq)
72 resp = new(types.AddTxResp)
73 clientAddr proto.AccountAddress
74 )
75 if clientAddr, err = crypto.PubKeyHash(privateKey.PubKey()); err != nil {
76 err = errors.Wrap(err, "get local account address failed")
77 return
78 }
79 // allocate nonce
80 nonceReq.Addr = clientAddr
81
82 if err = rpc.RequestBP(route.MCCNextAccountNonce.String(), nonceReq, nonceResp); err != nil {
83 err = errors.Wrap(err, "allocate create database transaction nonce failed")
84 return
85 }
86
87 req.Tx = types.NewCreateDatabase(&types.CreateDatabaseHeader{
88 Owner: clientAddr,
89 ResourceMeta: meta,
90 GasPrice: gasPrice,
91 AdvancePayment: advancePayment,
92 TokenType: types.Particle,
93 Nonce: nonceResp.Nonce,
94 })
95
96 if err = req.Tx.Sign(privateKey); err != nil {
97 err = errors.Wrap(err, "sign request failed")
98 return
99 }
100
101 if err = rpc.RequestBP(route.MCCAddTx.String(), req, resp); err != nil {
102 err = errors.Wrap(err, "call create database transaction failed")
103 return
104 }
105
106 dbID = proto.FromAccountAndNonce(clientAddr, uint32(nonceResp.Nonce))
107 dsn = fmt.Sprintf("cql://%s", string(dbID))
108 return
109}

Callers 1

TestFullProcessFunction · 0.92

Calls 6

PubKeyHashFunction · 0.92
NewCreateDatabaseFunction · 0.92
FromAccountAndNonceFunction · 0.92
PubKeyMethod · 0.80
SignMethod · 0.65
StringMethod · 0.45

Tested by 1

TestFullProcessFunction · 0.74