Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple contracts per account #7

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b4ae87a
Allowed multiple contracts per account
janezpodhostnik Sep 22, 2020
0637150
versions fix
janezpodhostnik Sep 25, 2020
408b8dd
Merge branch 'master' of github.com:onflow/flow-go into janez/multipl…
janezpodhostnik Sep 30, 2020
2bfaa26
change setCode to include name
janezpodhostnik Sep 30, 2020
2dcd742
Merge branch 'master' of github.com:onflow/flow-go into janez/multipl…
janezpodhostnik Sep 30, 2020
f628834
linting fixes
janezpodhostnik Sep 30, 2020
5d6fd8a
update to Cadence v0.10.0
turbolent Oct 2, 2020
0a1a00d
improve location resolution
turbolent Oct 2, 2020
54834a4
update to Cadence v0.10.0
turbolent Oct 2, 2020
9cc4630
fixed flakey tests and added tests
janezpodhostnik Oct 2, 2020
f85dd69
code review fixes
janezpodhostnik Oct 5, 2020
1ee29af
Merge branch 'master' of github.com:onflow/flow-go into janez/multipl…
janezpodhostnik Oct 5, 2020
364299f
integration tests fixes
janezpodhostnik Oct 6, 2020
fdb3161
code review fixes
janezpodhostnik Oct 6, 2020
9eea7db
flow-go-sdk version upgrade
janezpodhostnik Oct 6, 2020
b4dc9ba
Merge branch 'master' of github.com:onflow/flow-go into janez/multipl…
janezpodhostnik Oct 6, 2020
0549dfa
integration test fixes
janezpodhostnik Oct 6, 2020
2fc656f
tests fix
janezpodhostnik Oct 6, 2020
ee66335
test fix
janezpodhostnik Oct 6, 2020
3f1a7cc
test fix and dependency update
janezpodhostnik Oct 6, 2020
9aacffa
Merge branch 'bastian/multiple-contracts-per-account' into janez/mult…
turbolent Oct 6, 2020
b622992
increase timeout
turbolent Oct 6, 2020
d2933d3
removing legacy code reads
janezpodhostnik Oct 7, 2020
e3d281f
Merge branch 'janez/multiple-smart-contract-support' of github.com:on…
janezpodhostnik Oct 7, 2020
505266a
integration tests fix
janezpodhostnik Oct 7, 2020
e879168
test fix
janezpodhostnik Oct 7, 2020
ce0a237
test fix
janezpodhostnik Oct 7, 2020
f69c07f
Merge branch 'master' of github.com:onflow/flow-go into janez/multipl…
janezpodhostnik Oct 8, 2020
7de190e
add logging
zhangchiqing Oct 8, 2020
15755f8
test fixes
janezpodhostnik Oct 8, 2020
33a4841
Merge branch 'master' of github.com:onflow/flow-go into janez/multipl…
janezpodhostnik Oct 9, 2020
4d12e74
undo test wait time increase
janezpodhostnik Oct 9, 2020
6ee2399
Merge branch 'master' of github.com:onflow/flow-go into janez/multipl…
janezpodhostnik Oct 13, 2020
40a3999
renaming and switch to cbor
janezpodhostnik Oct 19, 2020
7b424c6
Update fvm/state/accounts.go
janezpodhostnik Oct 20, 2020
353c1b7
more renaming and using require in tests
janezpodhostnik Oct 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions access/legacy/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func MessageToTransaction(m *entitiesproto.Transaction, chain flow.Chain) (flow.
func TransactionToMessage(tb flow.TransactionBody) *entitiesproto.Transaction {
proposalKeyMessage := &entitiesproto.Transaction_ProposalKey{
Address: tb.ProposalKey.Address.Bytes(),
KeyId: uint32(tb.ProposalKey.KeyID),
KeyId: uint32(tb.ProposalKey.KeyIndex),
SequenceNumber: tb.ProposalKey.SequenceNumber,
}

Expand All @@ -91,7 +91,7 @@ func TransactionToMessage(tb flow.TransactionBody) *entitiesproto.Transaction {
for i, sig := range tb.PayloadSignatures {
payloadSigMessages[i] = &entitiesproto.Transaction_Signature{
Address: sig.Address.Bytes(),
KeyId: uint32(sig.KeyID),
KeyId: uint32(sig.KeyIndex),
Signature: sig.Signature,
}
}
Expand All @@ -101,7 +101,7 @@ func TransactionToMessage(tb flow.TransactionBody) *entitiesproto.Transaction {
for i, sig := range tb.EnvelopeSignatures {
envelopeSigMessages[i] = &entitiesproto.Transaction_Signature{
Address: sig.Address.Bytes(),
KeyId: uint32(sig.KeyID),
KeyId: uint32(sig.KeyIndex),
Signature: sig.Signature,
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ func AccountToMessage(a *flow.Account) (*entitiesproto.Account, error) {
return &entitiesproto.Account{
Address: a.Address.Bytes(),
Balance: a.Balance,
Code: a.Code,
Code: nil,
Keys: keys,
}, nil
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/util/cmd/exec-data-json-export/transaction_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type transactionInContext struct {
ProposalSequenceNumber uint64 `json:"proposal_sequence_number"`
AuthorizersAddressHex []string `json:"authorizers_address_hex"`
EnvelopeSize int `json:"envelope_size"`
// Address(hex) + ~ + SignerIndex + ~ + KeyID + ~ + Signature(hex)
// Address(hex) + ~ + SignerIndex + ~ + KeyIndex + ~ + Signature(hex)
CompactPayloadSignatures []string `json:"compact_payload_signatures"`
CompactEnvelopeSignatures []string `json:"compact_envelope_signatures"`
// ErrorMessage string `json:"error_message"`
Expand Down Expand Up @@ -102,13 +102,13 @@ func ExportExecutedTransactions(blockID flow.Identifier, dbPath string, outputPa

psig := make([]string, 0)
for _, s := range tx.PayloadSignatures {
cs := hex.EncodeToString(s.Address[:]) + "~" + fmt.Sprint(s.SignerIndex) + "~" + fmt.Sprint(s.KeyID) + "~" + hex.EncodeToString(s.Signature)
cs := hex.EncodeToString(s.Address[:]) + "~" + fmt.Sprint(s.SignerIndex) + "~" + fmt.Sprint(s.KeyIndex) + "~" + hex.EncodeToString(s.Signature)
psig = append(psig, cs)
}

esig := make([]string, 0)
for _, s := range tx.EnvelopeSignatures {
cs := hex.EncodeToString(s.Address[:]) + "~" + fmt.Sprint(s.SignerIndex) + "~" + fmt.Sprint(s.KeyID) + "~" + hex.EncodeToString(s.Signature)
cs := hex.EncodeToString(s.Address[:]) + "~" + fmt.Sprint(s.SignerIndex) + "~" + fmt.Sprint(s.KeyIndex) + "~" + hex.EncodeToString(s.Signature)
esig = append(esig, cs)
}

Expand All @@ -125,7 +125,7 @@ func ExportExecutedTransactions(blockID flow.Identifier, dbPath string, outputPa
GasLimit: tx.GasLimit,
PayerAddressHex: hex.EncodeToString(tx.Payer[:]),
ProposalKeyAddressHex: hex.EncodeToString(tx.ProposalKey.Address[:]),
ProposalKeyID: tx.ProposalKey.KeyID,
ProposalKeyID: tx.ProposalKey.KeyIndex,
ProposalSequenceNumber: tx.ProposalKey.SequenceNumber,
AuthorizersAddressHex: auths,
EnvelopeSize: computeEnvelopeSize(tx),
Expand Down
23 changes: 12 additions & 11 deletions engine/common/rpc/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func MessageToTransaction(m *entities.Transaction, chain flow.Chain) (flow.Trans
func TransactionToMessage(tb flow.TransactionBody) *entities.Transaction {
proposalKeyMessage := &entities.Transaction_ProposalKey{
Address: tb.ProposalKey.Address.Bytes(),
KeyId: uint32(tb.ProposalKey.KeyID),
KeyId: uint32(tb.ProposalKey.KeyIndex),
SequenceNumber: tb.ProposalKey.SequenceNumber,
}

Expand All @@ -88,7 +88,7 @@ func TransactionToMessage(tb flow.TransactionBody) *entities.Transaction {
for i, sig := range tb.PayloadSignatures {
payloadSigMessages[i] = &entities.Transaction_Signature{
Address: sig.Address.Bytes(),
KeyId: uint32(sig.KeyID),
KeyId: uint32(sig.KeyIndex),
Signature: sig.Signature,
}
}
Expand All @@ -98,7 +98,7 @@ func TransactionToMessage(tb flow.TransactionBody) *entities.Transaction {
for i, sig := range tb.EnvelopeSignatures {
envelopeSigMessages[i] = &entities.Transaction_Signature{
Address: sig.Address.Bytes(),
KeyId: uint32(sig.KeyID),
KeyId: uint32(sig.KeyIndex),
Signature: sig.Signature,
}
}
Expand Down Expand Up @@ -244,10 +244,10 @@ func MessageToAccount(m *entities.Account) (*flow.Account, error) {
}

return &flow.Account{
Address: flow.BytesToAddress(m.GetAddress()),
Balance: m.GetBalance(),
Code: m.GetCode(),
Keys: accountKeys,
Address: flow.BytesToAddress(m.GetAddress()),
Balance: m.GetBalance(),
Keys: accountKeys,
Contracts: m.Contracts,
}, nil
}

Expand All @@ -262,10 +262,11 @@ func AccountToMessage(a *flow.Account) (*entities.Account, error) {
}

return &entities.Account{
Address: a.Address.Bytes(),
Balance: a.Balance,
Code: a.Code,
Keys: keys,
Address: a.Address.Bytes(),
Balance: a.Balance,
Code: nil,
Keys: keys,
Contracts: a.Contracts,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion engine/execution/state/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestBootstrapLedger(t *testing.T) {
}

func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) {
var expectedStateCommitment, _ = hex.DecodeString("207ef54cec1605ff02a82d0382fe9a8851971007d2ef4a2e94426fd76cf8f133")
var expectedStateCommitment, _ = hex.DecodeString("49c03e8ca43c3925e8744f48a24d345d98f5b28fa6705c2e1b48d186f746b39c")

unittest.RunWithTempDir(t, func(dbDir string) {

Expand Down
12 changes: 6 additions & 6 deletions engine/execution/testutil/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@ import (
"github.com/onflow/flow-go/utils/unittest"
)

func CreateContractDeploymentTransaction(contract string, authorizer flow.Address, chain flow.Chain) *flow.TransactionBody {
func CreateContractDeploymentTransaction(contractName string, contract string, authorizer flow.Address, chain flow.Chain) *flow.TransactionBody {
encoded := hex.EncodeToString([]byte(contract))

return flow.NewTransactionBody().
SetScript([]byte(fmt.Sprintf(`transaction {
prepare(signer: AuthAccount, service: AuthAccount) {
signer.setCode("%s".decodeHex())
signer.contracts.add(name: "%s", code: "%s".decodeHex())
}
}`, encoded)),
}`, contractName, encoded)),
).
AddAuthorizer(authorizer).
AddAuthorizer(chain.ServiceAddress())
}

func CreateUnauthorizedContractDeploymentTransaction(contract string, authorizer flow.Address) *flow.TransactionBody {
func CreateUnauthorizedContractDeploymentTransaction(contractName string, contract string, authorizer flow.Address) *flow.TransactionBody {
encoded := hex.EncodeToString([]byte(contract))

return flow.NewTransactionBody().
SetScript([]byte(fmt.Sprintf(`transaction {
prepare(signer: AuthAccount) {
signer.setCode("%s".decodeHex())
signer.contracts.add(name: "%s", code: "%s".decodeHex())
}
}`, encoded)),
}`, contractName, encoded)),
).
AddAuthorizer(authorizer)
}
Expand Down
4 changes: 2 additions & 2 deletions engine/execution/testutil/fixtures_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ access(all) contract Container {
`

func DeployCounterContractTransaction(authorizer flow.Address, chain flow.Chain) *flow.TransactionBody {
return CreateContractDeploymentTransaction(CounterContract, authorizer, chain)
return CreateContractDeploymentTransaction("Container", CounterContract, authorizer, chain)
}

func DeployUnauthorizedCounterContractTransaction(authorizer flow.Address) *flow.TransactionBody {
return CreateUnauthorizedContractDeploymentTransaction(CounterContract, authorizer)
return CreateUnauthorizedContractDeploymentTransaction("Container", CounterContract, authorizer)
}

func CreateCounterTransaction(counter, signer flow.Address) *flow.TransactionBody {
Expand Down
2 changes: 1 addition & 1 deletion fvm/astCache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func TestProgramASTCacheAvoidRaceCondition(t *testing.T) {
}
wg.Wait()

location := runtime.AddressLocation(fvm.FlowTokenAddress(chain).Bytes())
location := runtime.AddressContractLocation{AddressLocation: fvm.FlowTokenAddress(chain).Bytes(), Name: "FlowToken"}

// Get cached program
var program *ast.Program
Expand Down
14 changes: 7 additions & 7 deletions fvm/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (b *BootstrapProcedure) deployFungibleToken() flow.Address {

err := b.vm.invokeMetaTransaction(
b.ctx,
deployContractTransaction(fungibleToken, contracts.FungibleToken()),
deployContractTransaction(fungibleToken, contracts.FungibleToken(), "FungibleToken"),
b.ledger,
)
if err != nil {
Expand Down Expand Up @@ -141,7 +141,7 @@ func (b *BootstrapProcedure) deployServiceAccount(service, fungibleToken, flowTo

err := b.vm.invokeMetaTransaction(
b.ctx,
deployContractTransaction(service, contract),
deployContractTransaction(service, contract, "FlowServiceAccount"),
b.ledger,
)
if err != nil {
Expand All @@ -166,7 +166,7 @@ func (b *BootstrapProcedure) mintInitialTokens(
const deployContractTransactionTemplate = `
transaction {
prepare(signer: AuthAccount) {
signer.setCode("%s".decodeHex())
signer.contracts.add(name: "%s", code: "%s".decodeHex())
}
}
`
Expand All @@ -175,7 +175,7 @@ const deployFlowTokenTransactionTemplate = `
transaction {
prepare(flowTokenAccount: AuthAccount, serviceAccount: AuthAccount) {
let adminAccount = serviceAccount
flowTokenAccount.setCode("%s".decodeHex(), adminAccount)
flowTokenAccount.contracts.add(name: "FlowToken", code: "%s".decodeHex(), adminAccount: adminAccount)
}
}
`
Expand All @@ -184,7 +184,7 @@ const deployFlowFeesTransactionTemplate = `
transaction {
prepare(flowFeesAccount: AuthAccount, serviceAccount: AuthAccount) {
let adminAccount = serviceAccount
flowFeesAccount.setCode("%s".decodeHex(), adminAccount)
flowFeesAccount.contracts.add(name: "FlowFees", code: "%s".decodeHex(), adminAccount: adminAccount)
}
}
`
Expand Down Expand Up @@ -220,10 +220,10 @@ transaction(amount: UFix64) {
}
`

func deployContractTransaction(address flow.Address, contract []byte) *TransactionProcedure {
func deployContractTransaction(address flow.Address, contract []byte, contractName string) *TransactionProcedure {
return Transaction(
flow.NewTransactionBody().
SetScript([]byte(fmt.Sprintf(deployContractTransactionTemplate, hex.EncodeToString(contract)))).
SetScript([]byte(fmt.Sprintf(deployContractTransactionTemplate, contractName, hex.EncodeToString(contract)))).
AddAuthorizer(address),
)
}
Expand Down
Loading