-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
native: drop Neo.Native.Deploy, move contract init to management cont…
…ract The contract is almost a stub at the moment, though it does deploy other contracts.
- Loading branch information
1 parent
090bee8
commit ff789f6
Showing
15 changed files
with
127 additions
and
98 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package native | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
|
||
"github.com/nspcc-dev/neo-go/pkg/core/interop" | ||
"github.com/nspcc-dev/neo-go/pkg/core/state" | ||
) | ||
|
||
// Management is contract-managing native contract. | ||
type Management struct { | ||
interop.ContractMD | ||
|
||
lock sync.RWMutex | ||
isValid bool | ||
nextID int32 | ||
} | ||
|
||
const ( | ||
managementName = "Neo Contract Management" | ||
prefixContract = 8 | ||
prefixNextAvailableId = 15 | ||
) | ||
|
||
// newManagement creates new Management native contract. | ||
func newManagement() *Management { | ||
var m = &Management{ContractMD: *interop.NewContractMD(managementName)} | ||
|
||
return m | ||
} | ||
|
||
// Metadata implements Contract interface. | ||
func (m *Management) Metadata() *interop.ContractMD { | ||
return &m.ContractMD | ||
} | ||
|
||
// OnPersist implements Contract interface. | ||
func (m *Management) OnPersist(ic *interop.Context) error { | ||
if ic.Block.Index != 0 { // We're only deploying at 0 at the moment. | ||
return nil | ||
} | ||
|
||
for _, native := range ic.Natives { | ||
md := native.Metadata() | ||
|
||
cs := &state.Contract{ | ||
ID: md.ContractID, | ||
Hash: md.Hash, | ||
Script: md.Script, | ||
Manifest: md.Manifest, | ||
} | ||
if err := ic.DAO.PutContractState(cs); err != nil { | ||
return err | ||
} | ||
if err := native.Initialize(ic); err != nil { | ||
return fmt.Errorf("initializing %s native contract: %w", md.Name, err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// PostPersist implements Contract interface. | ||
func (m *Management) PostPersist(_ *interop.Context) error { | ||
return nil | ||
} | ||
|
||
// Initialize implements Contract interface. | ||
func (m *Management) Initialize(_ *interop.Context) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.