Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Commits
a5b51a8f
Commit
a5b51a8f
authored
2 years ago
by
Richard T. Carback III
Committed by
Jono Wenger
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fixed tests and implementation for indexedDB. Autoincrement and uuid return is working now
parent
5031af59
No related branches found
No related tags found
2 merge requests
!60
Revert "Fail a test to be sure it works"
,
!8
Updates to match the client fullyDecentrilizedChannels branch
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
indexedDb/implementation.go
+44
-14
44 additions, 14 deletions
indexedDb/implementation.go
indexedDb/implementation_test.go
+15
-4
15 additions, 4 deletions
indexedDb/implementation_test.go
indexedDb/init.go
+5
-0
5 additions, 0 deletions
indexedDb/init.go
indexedDb/model.go
+5
-4
5 additions, 4 deletions
indexedDb/model.go
with
69 additions
and
22 deletions
indexedDb/implementation.go
+
44
−
14
View file @
a5b51a8f
...
@@ -83,7 +83,7 @@ func (w *wasmModel) JoinChannel(channel *cryptoBroadcast.Channel) {
...
@@ -83,7 +83,7 @@ func (w *wasmModel) JoinChannel(channel *cryptoBroadcast.Channel) {
}
}
// Perform the operation
// Perform the operation
_
,
err
=
store
.
Add
(
channelObj
)
_
,
err
=
store
.
Put
(
channelObj
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to Add Channel: %+v"
,
err
))
"Unable to Add Channel: %+v"
,
err
))
...
@@ -260,8 +260,29 @@ func buildMessage(channelID, messageID, parentID []byte, nickname,
...
@@ -260,8 +260,29 @@ func buildMessage(channelID, messageID, parentID []byte, nickname,
}
}
}
}
// // uuidHelper is ap rivate helper to determine an autoincremented
// // uuid value for a given store. The way it works right now
// // is by counting all the objects and returning count + 1, but
// // there may be a better way to retrieve this value with the pkName
// func (w *wasmModel) uuidHelper(pkName, storeName string) uint64 {
// w.db.
// // Prepare the Transaction
// txn, err := w.db.Transaction(idb.TransactionReadWrite, messageStoreName)
// if err != nil {
// jww.
// return 0, errors.Errorf("Unable to create Transaction: %+v",
// err)
// }
// store, err := txn.ObjectStore(storeName)
// if err != nil {
// return 0, errors.Errorf("Unable to get ObjectStore: %+v", err)
// }
// }
// receiveHelper is a private helper for receiving any sort of message.
// receiveHelper is a private helper for receiving any sort of message.
func
(
w
*
wasmModel
)
receiveHelper
(
newMessage
*
Message
)
(
uint64
,
error
)
{
func
(
w
*
wasmModel
)
receiveHelper
(
newMessage
*
Message
)
(
uint64
,
error
)
{
// Convert to jsObject
// Convert to jsObject
newMessageJson
,
err
:=
json
.
Marshal
(
newMessage
)
newMessageJson
,
err
:=
json
.
Marshal
(
newMessage
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -272,6 +293,13 @@ func (w *wasmModel) receiveHelper(newMessage *Message) (uint64, error) {
...
@@ -272,6 +293,13 @@ func (w *wasmModel) receiveHelper(newMessage *Message) (uint64, error) {
return
0
,
errors
.
Errorf
(
"Unable to marshal Message: %+v"
,
err
)
return
0
,
errors
.
Errorf
(
"Unable to marshal Message: %+v"
,
err
)
}
}
// NOTE: This is weird, but correct. When the "ID" field is 0, we
// unset it from the JSValue so that it is auto-populated and
// incremented
if
newMessage
.
ID
==
0
{
messageObj
.
JSValue
()
.
Delete
(
"id"
)
}
// Prepare the Transaction
// Prepare the Transaction
txn
,
err
:=
w
.
db
.
Transaction
(
idb
.
TransactionReadWrite
,
messageStoreName
)
txn
,
err
:=
w
.
db
.
Transaction
(
idb
.
TransactionReadWrite
,
messageStoreName
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -284,7 +312,7 @@ func (w *wasmModel) receiveHelper(newMessage *Message) (uint64, error) {
...
@@ -284,7 +312,7 @@ func (w *wasmModel) receiveHelper(newMessage *Message) (uint64, error) {
}
}
// Perform the upsert (put) operation
// Perform the upsert (put) operation
put
Req
,
err
:=
store
.
Put
(
messageObj
)
add
Req
,
err
:=
store
.
Put
(
messageObj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
errors
.
Errorf
(
"Unable to upsert Message: %+v"
,
err
)
return
0
,
errors
.
Errorf
(
"Unable to upsert Message: %+v"
,
err
)
}
}
...
@@ -296,11 +324,12 @@ func (w *wasmModel) receiveHelper(newMessage *Message) (uint64, error) {
...
@@ -296,11 +324,12 @@ func (w *wasmModel) receiveHelper(newMessage *Message) (uint64, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
errors
.
Errorf
(
"Upserting Message failed: %+v"
,
err
)
return
0
,
errors
.
Errorf
(
"Upserting Message failed: %+v"
,
err
)
}
}
res
,
_
:=
put
Req
.
Result
()
res
,
_
:=
add
Req
.
Result
()
uuid
:=
uint64
(
res
.
Int
())
uuid
:=
uint64
(
res
.
Int
())
jww
.
DEBUG
.
Printf
(
jww
.
DEBUG
.
Printf
(
"Successfully stored message from %s, id %d"
,
"Successfully stored message from %s, id %d"
,
newMessage
.
Codename
,
uuid
)
newMessage
.
Codename
,
uuid
)
return
uuid
,
nil
return
uuid
,
nil
}
}
...
@@ -368,16 +397,17 @@ func (w *wasmModel) dump(objectStoreName string) ([]string, error) {
...
@@ -368,16 +397,17 @@ func (w *wasmModel) dump(objectStoreName string) ([]string, error) {
jww
.
DEBUG
.
Printf
(
"%s values:"
,
objectStoreName
)
jww
.
DEBUG
.
Printf
(
"%s values:"
,
objectStoreName
)
results
:=
make
([]
string
,
0
)
results
:=
make
([]
string
,
0
)
ctx
,
cancel
:=
newContext
()
ctx
,
cancel
:=
newContext
()
err
=
cursorRequest
.
Iter
(
ctx
,
func
(
cursor
*
idb
.
CursorWithValue
)
error
{
err
=
cursorRequest
.
Iter
(
ctx
,
value
,
err
:=
cursor
.
Value
()
func
(
cursor
*
idb
.
CursorWithValue
)
error
{
if
err
!=
nil
{
value
,
err
:=
cursor
.
Value
()
return
err
if
err
!=
nil
{
}
return
err
valueStr
:=
utils
.
JsToJson
(
value
)
}
results
=
append
(
results
,
valueStr
)
valueStr
:=
utils
.
JsToJson
(
value
)
jww
.
DEBUG
.
Printf
(
"- %v"
,
valueStr
)
results
=
append
(
results
,
valueStr
)
return
nil
jww
.
DEBUG
.
Printf
(
"- %v"
,
valueStr
)
})
return
nil
})
cancel
()
cancel
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
WithMessagef
(
parentErr
,
return
nil
,
errors
.
WithMessagef
(
parentErr
,
...
...
This diff is collapsed.
Click to expand it.
indexedDb/implementation_test.go
+
15
−
4
View file @
a5b51a8f
...
@@ -11,6 +11,7 @@ package indexedDb
...
@@ -11,6 +11,7 @@ package indexedDb
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"os"
"os"
"testing"
"testing"
"time"
"time"
...
@@ -125,21 +126,29 @@ func TestWasmModel_JoinChannel_LeaveChannel(t *testing.T) {
...
@@ -125,21 +126,29 @@ func TestWasmModel_JoinChannel_LeaveChannel(t *testing.T) {
// Test wasmModel.UpdateSentStatus happy path and ensure fields don't change.
// Test wasmModel.UpdateSentStatus happy path and ensure fields don't change.
func
TestWasmModel_UUIDTest
(
t
*
testing
.
T
)
{
func
TestWasmModel_UUIDTest
(
t
*
testing
.
T
)
{
testString
:=
"test"
testString
:=
"test
Hello
"
testMsgId
:=
channel
.
MakeMessageID
([]
byte
(
testString
))
testMsgId
:=
channel
.
MakeMessageID
([]
byte
(
testString
))
eventModel
,
err
:=
newWasmModel
(
testString
)
eventModel
,
err
:=
newWasmModel
(
testString
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"%+v"
,
err
)
t
.
Fatalf
(
"%+v"
,
err
)
}
}
cid
:=
channel
.
Identity
{}
cid
:=
channel
.
Identity
{
Codename
:
"codename123"
,
PubKey
:
[]
byte
{
8
,
6
,
7
,
5
},
Color
:
"#FFFFFF"
,
Extension
:
"gif"
,
CodesetVersion
:
0
,
}
uuids
:=
make
([]
uint64
,
10
)
uuids
:=
make
([]
uint64
,
10
)
for
i
:=
0
;
i
<
10
;
i
++
{
for
i
:=
0
;
i
<
10
;
i
++
{
// Store a test message
// Store a test message
testMsg
:=
buildMessage
([]
byte
(
testString
),
testMsgId
.
Bytes
(),
testMsg
:=
buildMessage
([]
byte
(
testString
),
nil
,
testString
,
testString
,
cid
,
time
.
Now
(),
testMsgId
.
Bytes
(),
nil
,
testString
,
testString
+
fmt
.
Sprintf
(
"%d"
,
i
),
cid
,
time
.
Now
(),
time
.
Second
,
channels
.
Sent
)
time
.
Second
,
channels
.
Sent
)
uuid
,
err
:=
eventModel
.
receiveHelper
(
testMsg
)
uuid
,
err
:=
eventModel
.
receiveHelper
(
testMsg
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -148,6 +157,8 @@ func TestWasmModel_UUIDTest(t *testing.T) {
...
@@ -148,6 +157,8 @@ func TestWasmModel_UUIDTest(t *testing.T) {
uuids
[
i
]
=
uuid
uuids
[
i
]
=
uuid
}
}
eventModel
.
dump
(
messageStoreName
)
for
i
:=
0
;
i
<
10
;
i
++
{
for
i
:=
0
;
i
<
10
;
i
++
{
for
j
:=
i
+
1
;
j
<
10
;
j
++
{
for
j
:=
i
+
1
;
j
<
10
;
j
++
{
if
uuids
[
i
]
==
uuids
[
j
]
{
if
uuids
[
i
]
==
uuids
[
j
]
{
...
...
This diff is collapsed.
Click to expand it.
indexedDb/init.go
+
5
−
0
View file @
a5b51a8f
...
@@ -82,6 +82,11 @@ func v1Upgrade(db *idb.Database) error {
...
@@ -82,6 +82,11 @@ func v1Upgrade(db *idb.Database) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
_
,
err
=
messageStore
.
CreateIndex
(
messageStoreMessageIndex
,
js
.
ValueOf
(
messageStoreMessage
),
indexOpts
)
if
err
!=
nil
{
return
err
}
_
,
err
=
messageStore
.
CreateIndex
(
messageStoreChannelIndex
,
_
,
err
=
messageStore
.
CreateIndex
(
messageStoreChannelIndex
,
js
.
ValueOf
(
messageStoreChannel
),
indexOpts
)
js
.
ValueOf
(
messageStoreChannel
),
indexOpts
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
indexedDb/model.go
+
5
−
4
View file @
a5b51a8f
...
@@ -30,6 +30,7 @@ const (
...
@@ -30,6 +30,7 @@ const (
messageStorePubkeyIndex
=
"pubkey_index"
messageStorePubkeyIndex
=
"pubkey_index"
// Message keyPath names (must match json struct tags).
// Message keyPath names (must match json struct tags).
messageStoreMessage
=
"channel_id"
messageStoreChannel
=
"channel_id"
messageStoreChannel
=
"channel_id"
messageStoreParent
=
"parent_message_id"
messageStoreParent
=
"parent_message_id"
messageStoreTimestamp
=
"timestamp"
messageStoreTimestamp
=
"timestamp"
...
@@ -59,10 +60,10 @@ type Message struct {
...
@@ -59,10 +60,10 @@ type Message struct {
Text
string
`json:"text"`
Text
string
`json:"text"`
// User cryptographic IDentity struct -- could be pulled out
// User cryptographic IDentity struct -- could be pulled out
Pubkey
[]
byte
`json:"pubkey"`
// Index
Pubkey
[]
byte
`json:"pubkey"`
// Index
Honorific
string
`json:"honorific"`
//
Honorific string `json:"honorific"`
Adjective
string
`json:"adjective"`
//
Adjective string `json:"adjective"`
Noun
string
`json:"noun"`
//
Noun string `json:"noun"`
Codename
string
`json:"codename"`
Codename
string
`json:"codename"`
Color
string
`json:"color"`
Color
string
`json:"color"`
Extension
string
`json:"extension"`
Extension
string
`json:"extension"`
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment