Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

invokeTransferFrom() is problem in erc20 example #27

Closed
TedKang opened this issue Oct 27, 2019 · 4 comments
Closed

invokeTransferFrom() is problem in erc20 example #27

TedKang opened this issue Oct 27, 2019 · 4 comments

Comments

@TedKang
Copy link

TedKang commented Oct 27, 2019

Hi, I ran the erc20 example and it seems to be a problem with invokeTransferFrom().

allowance, err := getAllowance(c, fromMspId, fromCertId, invoker.GetMSPID(), invoker.GetID())

In the above code, the argument value corresponding to 'from' and the argument value position of 'invoker' seem to be reversed.

Please confirm.

Thanks

@vitiko
Copy link
Collaborator

vitiko commented Oct 30, 2019

// getAllowance gets amount of token allowed by wallet owner to spend by spender
func getAllowance(c r.Context, ownerMspId, ownerCertId, spenderMspId, spenderCertId string) (int, error) {
	return c.State().GetInt(allowanceKey(ownerMspId, ownerCertId, spenderMspId, spenderCertId), 0)
}

in the invokeTransferFrom() function

  • invoker.GetMSPID() and invoker.GetID() are spender requisites
  • fromMspId, fromCertId are wallet owner requisites

@TedKang
Copy link
Author

TedKang commented Oct 31, 2019

// getAllowance gets amount of token allowed by wallet owner to spend by spender
func getAllowance(c r.Context, ownerMspId, ownerCertId, spenderMspId, spenderCertId string) (int, error) {
	return c.State().GetInt(allowanceKey(ownerMspId, ownerCertId, spenderMspId, spenderCertId), 0)
}

in the invokeTransferFrom() function

  • invoker.GetMSPID() and invoker.GetID() are spender requisites
  • fromMspId, fromCertId are wallet owner requisites

you're right. I mean, it would be the token owner to invoke transferFrom() in the code above. So I think the Invoker's MspId should be placed in ownerMspId when calling getAllowance ().

What i understood...

in the invokeTransferFrom() function

  • invoker.GetMSPId(), invoker.GetId() >> token owner
  • fromMspId, fromCertId >> token Sender

Please reply if I misunderstand.

@vitiko
Copy link
Collaborator

vitiko commented Oct 31, 2019

invokeTransferFrom() is invoked not by token owner, but by spender, who have allowance to spend some amount from token owner, so:

  • invoker.GetMSPId(), invoker.GetId() - spender
  • fromMspId, fromCertId - owner
  • toMspId, toCertId - recipient

you can see example in test https://github.com/s7techlab/cckit/blob/master/examples/erc20/erc20_test.go#L101

@TedKang
Copy link
Author

TedKang commented Oct 31, 2019

@vitiko Thanks for answer.
I misunderstood the concept.

@TedKang TedKang closed this as completed Oct 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants