feat(vm): add CurrentCaller field to context to represent the current invocation address in the case of cross-contract invocation

This commit is contained in:
dawn-to-dusk 2021-03-24 14:09:56 +08:00
parent d7c052d41d
commit 95f3faf306
2 changed files with 7 additions and 0 deletions

View File

@ -27,6 +27,10 @@ func (b *BoltStubImpl) Callee() string {
return b.ctx.Callee.String()
}
func (b *BoltStubImpl) CurrentCaller() string {
return b.ctx.CurrentCaller.String()
}
func (b *BoltStubImpl) Logger() logrus.FieldLogger {
return b.ctx.Logger
}
@ -126,6 +130,7 @@ func (b *BoltStubImpl) CrossInvoke(address, method string, args ...*pb.Arg) *bol
ctx := &vm.Context{
Caller: b.bvm.ctx.Caller,
Callee: addr,
CurrentCaller: b.bvm.ctx.Callee,
Ledger: b.bvm.ctx.Ledger,
TransactionIndex: b.bvm.ctx.TransactionIndex,
TransactionHash: b.bvm.ctx.TransactionHash,

View File

@ -11,6 +11,7 @@ import (
type Context struct {
Caller *types.Address
Callee *types.Address
CurrentCaller *types.Address
Ledger ledger.Ledger
TransactionIndex uint64
TransactionHash *types.Hash
@ -24,6 +25,7 @@ func NewContext(tx *pb.Transaction, txIndex uint64, data *pb.TransactionData, le
return &Context{
Caller: tx.From,
Callee: tx.To,
CurrentCaller: tx.From,
Ledger: ledger,
TransactionIndex: txIndex,
TransactionHash: tx.TransactionHash,