mirror of
https://github.com/status-im/status-console-client.git
synced 2025-02-23 16:18:23 +00:00
add -add-contact flag (#71)
This commit is contained in:
parent
98b7b1f515
commit
088fab977d
75
main.go
75
main.go
@ -39,6 +39,7 @@ var (
|
||||
|
||||
// flags acting like commands
|
||||
createKeyPair = fs.Bool("create-key-pair", false, "creates and prints a key pair instead of running")
|
||||
addContact = fs.String("add-contact", "", "add contact using format: type,name[,public-key] where type can be 'private' or 'public' and 'public-key' is required for 'private' type")
|
||||
|
||||
// flags for in-proc node
|
||||
dataDir = fs.String("data-dir", filepath.Join(os.TempDir(), "status-term-client"), "data directory for Ethereum node")
|
||||
@ -124,34 +125,11 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
// initialize protocol
|
||||
var (
|
||||
messenger *client.MessengerV2
|
||||
)
|
||||
|
||||
if *providerURI != "" {
|
||||
messenger, err = createMessengerWithURI(*providerURI, privateKey, db)
|
||||
if err != nil {
|
||||
exitErr(err)
|
||||
}
|
||||
} else {
|
||||
messenger, err = createMessengerInProc(privateKey, db)
|
||||
if err != nil {
|
||||
exitErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
adambContact, err := client.ContactWithPublicKey("adamb", "0x0493ac727e70ea62c4428caddf4da301ca67b699577988d6a782898acfd813addf79b2a2ca2c411499f2e0a12b7de4d00574cbddb442bec85789aea36b10f46895")
|
||||
if err != nil {
|
||||
exitErr(err)
|
||||
}
|
||||
|
||||
// Manage initial contacts.
|
||||
if contacts, err := db.Contacts(); len(contacts) == 0 || err != nil {
|
||||
debugContacts := []client.Contact{
|
||||
{Name: "status", Type: client.ContactPublicRoom, Topic: "status"},
|
||||
{Name: "status-core", Type: client.ContactPublicRoom, Topic: "status-core"},
|
||||
{Name: "testing-adamb", Type: client.ContactPublicRoom, Topic: "testing-adamb"},
|
||||
adambContact,
|
||||
}
|
||||
uniqueContacts := []client.Contact{}
|
||||
for _, c := range debugContacts {
|
||||
@ -170,6 +148,55 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle add contact.
|
||||
if *addContact != "" {
|
||||
options := strings.Split(*addContact, ",")
|
||||
|
||||
var c client.Contact
|
||||
|
||||
if len(options) == 2 && options[0] == "public" {
|
||||
c = client.Contact{
|
||||
Name: options[1],
|
||||
Type: client.ContactPublicRoom,
|
||||
Topic: options[1],
|
||||
}
|
||||
} else if len(options) == 3 && options[0] == "private" {
|
||||
c, err = client.ContactWithPublicKey(options[1], options[2])
|
||||
if err != nil {
|
||||
exitErr(err)
|
||||
}
|
||||
} else {
|
||||
exitErr(errors.Errorf("invalid -add-contact value"))
|
||||
}
|
||||
|
||||
exists, err := db.ContactExist(c)
|
||||
if err != nil {
|
||||
exitErr(err)
|
||||
}
|
||||
if !exists {
|
||||
if err := db.SaveContacts([]client.Contact{c}); err != nil {
|
||||
exitErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// initialize protocol
|
||||
var (
|
||||
messenger *client.MessengerV2
|
||||
)
|
||||
|
||||
if *providerURI != "" {
|
||||
messenger, err = createMessengerWithURI(*providerURI, privateKey, db)
|
||||
if err != nil {
|
||||
exitErr(err)
|
||||
}
|
||||
} else {
|
||||
messenger, err = createMessengerInProc(privateKey, db)
|
||||
if err != nil {
|
||||
exitErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
// run in a goroutine to show the UI faster
|
||||
go func() {
|
||||
if err := messenger.Start(); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user