// Write the changes into the tree.
Write the changes into the tree.
// Write the changes into the tree .
func (c *CollapseContext) Flush() error {
	if c.checksum != c.tree.Checksum() {
		return errors.Errorf(
			"stale state, the state has been modified. got merkle %x but expected %x.",
			c.tree.Checksum(), c.checksum,
		)
	}
	WriteAccountsLen(c.tree, c.accountLen)
	for _, id := range c.accountIDs {
		if bal, ok := c.balances[id]; ok {
			WriteAccountBalance(c.tree, id, bal)
		}
		if stake, ok := c.stakes[id]; ok {
			WriteAccountStake(c.tree, id, stake)
		}
		if reward, ok := c.rewards[id]; ok {
			WriteAccountReward(c.tree, id, reward)
		}
		if gasBal, ok := c.contractGasBalances[id]; ok {
			WriteAccountContractGasBalance(c.tree, id, gasBal)
		}
		if code, ok := c.contracts[id]; ok {
			WriteAccountContractCode(c.tree, id, code)
		}
		if vm, ok := c.contractVMs[id]; ok {
			SaveContractMemorySnapshot(c.tree, id, vm.Memory)
			SaveContractGlobals(c.tree, id, vm.Globals)
		}
	}
	return nil
}
func ( c * CollapseContext ) Flush ( ) error { if c . checksum != c . tree . Checksum ( ) { return errors . Errorf ( " " , c . tree . Checksum ( ) , c . checksum , ) } WriteAccountsLen ( c . tree , c . accountLen ) for _ , id := range c . accountIDs { if bal , ok := c . balances [ id ] ; ok { WriteAccountBalance ( c . tree , id , bal ) } if stake , ok := c . stakes [ id ] ; ok { WriteAccountStake ( c . tree , id , stake ) } if reward , ok := c . rewards [ id ] ; ok { WriteAccountReward ( c . tree , id , reward ) } if gasBal , ok := c . contractGasBalances [ id ] ; ok { WriteAccountContractGasBalance ( c . tree , id , gasBal ) } if code , ok := c . contracts [ id ] ; ok { WriteAccountContractCode ( c . tree , id , code ) } if vm , ok := c . contractVMs [ id ] ; ok { SaveContractMemorySnapshot ( c . tree , id , vm . Memory ) SaveContractGlobals ( c . tree , id , vm . Globals ) } } return nil }
Write the changes into the tree.
Write the changes into the tree .