avatarSajal Dulal

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2023

Abstract

overy system delivers a seamless user design with the high accessibility users have come to expect. If a user forgets their password on Mogul, they go through a familiar front-end experience similar to resetting an email or social media password. They click on a ‘Forgot Password’ button, a link is sent, they receive an email, click the link, and the password is reset. However, on the back-end, Mogul built a smart wallet system using smart contracts for decentralized wallet recoverability. When users reset a wallet, they actually create a new authentication wallet that is programmed to have the capabilities of interacting with the smart wallet. Yet, on the front-end to the user, it looks like a simple password reset.</p><ul><li><b>Manual Transaction Signatures Eliminated:</b></li></ul><p id="f765">Users can send free and frictionless transactions within the platform without manual signatures. When you use other DeFi wallets, you generally have to interact with a Web 3 interface to manually confirm a transaction and pay a costly gas fee, especially as the network congests. For example, with Metamask and Web3, a user needs to give permissions to access their wallet and then the user needs to confirm the transaction:</p><figure id="5453"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*2Mf9SQSXGWdh9ndV"><figcaption></figcaption></figure><p id="333b">This process would need to happen for each action on Mogul. Not everyone who could benefit from Mogul’s technology is able to understand the nuances involved in a blockchain transaction, so Mogul offers sponsored, frictionless in-platform actions.</p><p id="5ebc">While other wallets require tech-savviness just to maneuver around, Mogul has re-engineered an incredibly complex system in a very simple way.</p><h1 id="8d0a">Smart Wallet Recovery Done Right</h1><figure id="ec20"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*DL3FUoeScVR5WMIa"><figcaption></figcaption></figure><p id="c212">Our wallet recovery process u

Options

ses the Mogul Guardian by default, which allows for safe and secure decentralized recoverability. This system provides a user with a new authentication wallet through a standard password reset flow.</p><p id="4c95">The system delivers a new authentication wallet to communicate with user funds.</p><p id="c638">A Mogul user can choose between using the default Mogul Guardian system, or reset their guardian(s) to their preference where more than one Guardian can be chosen. Guardians could be friends, hardware wallets, or a mixture of both. Thus, users can create a multi-channel authentication system for decentralized password and key recovery.</p><p id="c957">For example, if a user doesn’t want to use the Mogul Guardian, that user can designate Tracy (or Tracy, Bob, and Alice) as the guardian(s) and thereby make them the only entity that can change the authentication wallet, requiring their wallet’s permissions to do so.</p><p id="732c">The film industry can benefit from the Mogul Smart Wallet because it is easy-to-use and does not require the tech know-how that was asked from previous generations of blockchain wallets.</p><p id="a531">Mogul removes major points of friction to deliver a seamless end-user experience that makes using blockchain technology feel as natural as using the Internet when browsing the web.</p><p id="eaf7">We are always listening to our users. We welcome suggestions and feedback through our <a href="https://mogulproductions.com/contact">contact page</a>.</p><p id="c69c"><b>ABOUT MOGUL PRODUCTIONS (MOGUL)</b> <i>Mogul Productions, established 2019, is a blockchain-based film financier and production company with a presence in Canada, the United States of America and Europe.</i></p><p id="ed5a"><i>The Mogul platform connects contributors, film industry professionals and fans through technology that allows all users to engage and participate with each project throughout theirs entire lifecycle, from financing through to production and distribution.</i></p></article></body>

Pointers and Passby value/reference in GOlang

This is the fourth article in the “Getting Started with GOlang” series. If you have not checked out the previous article please check it out before diving into this. 1. Getting started with GOlang 2. Slices, Custom Types and Receiver Functions(methods) in GOlang 3. Structs and Maps in GOlang 4. Pointers and Passby value/reference in GOlang 5. Interfaces in GOlang

Before understanding pointers, let's see an example using structs in GO. If you do not have a clear understanding regarding structs in go, please visit my previous article about it.

Create a new directory and inside it create a main.go file. Paste the following code inside it.

package main
import "fmt"
type student struct {
 firstName string
 lastName  string
}
func main() {
 Peter := student{firstName: "Peter", lastName: "Parker"}
Peter.changeFirstName("Peterson")
Peter.print()
}
func (s student) print() {
 fmt.Println("First Name: ", s.firstName, " Last Name: ", s.lastName)
}
func (s student) changeFirstName(f string) {
 s.firstName = f
}

Now, this is very similar to the struct example in the previous article. The only difference is that there is another receiver function named changeFirstName for the type student. It also takes another string as an argument and replaces the firstName with the provided string.

So basically, we replaced “Peter” with “Peterson” right? The answer is both YES and NO. Now run the program with go run main.go and see the output. The firstName is still “Peter”, which is the evidence for NO.

Now, remove the following line

Peter.print()

And add the following line inside the changeFirstName function, at the end.

s.print()

Save and run the file again. Now you see the firstName was “Peterson”. That is the evidence for YES. So, what exactly is happening here.

What happens is, when we pass a value inside a function, then a new instance of the value is created inside the function, which is a copy of the value. This holds true also for the receiver functions.

So, s inside the function changeFirstName is a copy of Peter but is not Peter. So, when we change the value of s, its value changes but the original value Peter is unaffected.

Now, replace all the code from main.go by:

package main
import "fmt"
type student struct {
 firstName string
 lastName  string
}
func main() {
 Peter := student{firstName: "Peter", lastName: "Parker"}
PeterPointer := &Peter
PeterPointer.changeFirstName("Peterson")
Peter.print()
}
func (s student) print() {
 fmt.Println("First Name: ", s.firstName, " Last Name: ", s.lastName)
}
func (sp *student) changeFirstName(f string) {
 (*sp).firstName = f
}

There are only a few changes made. Let's go to the line: PeterPointer := &Peter What does this &Peter mean, even more so, what does & mean? To understand this, we need to understand the meaning of Pointer. Things get a little intense here. Read it thoroughly, we shall go into small details to make things clear.

POINTERS

Peter is a variable that stores some kind of value (in our case a struct). This could be said as Peter is a representation of a value stored in a certain address/location in the memory of the computer. So, when we print Peter, we see the value stored in that memory address.

When Peter is passed into our function, a new variable s is created with identical values, but it will be stored in another memory location, with a different address. And when we change the value of s, it changes the value stored in it’s location but the value stored in the location represented by Peter is unaffected. That is why, Peter remained unchanged. This is what we call passby Value.

Now, by adding & in front of a variable it returns the memory address of the variable. So, when what mean by the line PeterPointer := &Peter is that we are assigning the memory address of variable Peter to PeterPointer (which is also another variable). These kinds of variable that contain the memory address of another variable are called pointers. Cause what it is essentially doing is, pointing towards the memory address that has the actual value.

And you can also see the line with (*sp). What * does is, if you put it in front of a memory address (pointer), it gives you access to the values present in the memory address ( that the pointer contains). So, if we write *PeterPointer , then it would represent the values inside the memory address that PeterPointer holds, which is Peter. so Basically, (*PeterPointer == Peter ) is true.

Now, Let's look at the line :

PeterPointer.changeFirstName("Peterson")

And function:

func (sp *student) changeFirstName(f string) {
 (*sp).firstName = f
}

Here, PeterPointer is not a struct of type student, but a pointer to a struct type student so if we want to use the receiver function for a pointer, the receiver type must be changed. Hence (sp *student) is used instead of (s student) that we previously used. And in the case of types in GO, * is added in front of a type to denote that, we are actually passing a pointer of that type, not the actual variable.

Now, stay with me here, as I said, when we pass a variable to a function, then a new variable is created with identical values but in a different memory location. So, s in the function changeFirstName, is also a new variable but it contains the same values as by PeterPointer, which is the memory address of the variable Peter.

So, as *PeterPointer, represents the value inside the memory address it contains, which is Peter. Similarly, *sp, also represents the same value inside Peter, as it also contains the same memory address. So, basically *sp == Peter is true And finally, when we make the changes to (*sp).firstName, the actual values of the variable Peter is changed. And this is what we called, passby reference because instead of the actual values, a reference address is passed which is then used to make changes to the actual value. Now, run the program, you should see that the values inside the struct Peter actually changes as per our need.

Now, there is one simple trick in going to make our life easier. Go ahead and delete the line:

PeterPointer := &Peter

And change the line following it to:

Peter.changeFirstName("Peterson")

But, Do not make any changes to the function. Try running the program, you will see the same results.

This is because, in GO, if we want to take the address of the variable we are using, then we do not need to specify it at the calling end. Specifying the nature of the passing (value or reference) at the function is sufficient, it automatically uses the address of the variable in use.

I hope this makes things regarding Pointer and Passby value/reference in a function clear. If there are any questions feel free to leave a response. Stay tuned for more articles regarding GO. Happy Coding :)

Pointers
Go
Programming
Tutorial
Beginner
Recommended from ReadMedium